When we run the packaging script npm run build
or package ios weexpack build ios
, we may encounter the following error
ERROR in index.js from UglifyJs
Unexpected token:punc (() [index.js:198,8])...
This is because webpack did not successfully convert the ES6 syntax when packaging the vue file.
The solution is very simple, just add babel-preset-es2015
plugin
$ npm install --save-div babel-preset-es2015
ps: babel-loader
and babel-core
should be installed by default, if not installed, please reinstall
Find the rules of /\.js$/
and modify
{
test: /\.js$/,
use: [{
loader: 'babel-loader',
options: {
presets: ['es2015']
}
}]
}
content
{
"presets": ["es2015"]
}
Re-run the packaging script to check the effect, the instruction depends on the situation
$ npm run build