I have 2 Vue-Cli webpack projects (ClientApp and Lib). Lib is my components library (shared with other projects)
When I build my project ClientApp npm run build
, I have the following error:
ERROR in static/js/app.d08a24ce0e8d0438ce68.js from UglifyJs
Unexpected token: operator (>) [C:/.../Lib/src/tools/escape-key.js:3,0][static/js/app.d08a24ce0e8d0438ce68.js:17468,38]
It seems like the error comes from an arrow function in the file escape-key.js
.
This is ES6 syntax and UglifyJS can't parse this.
Shouldn't Babel go first, before Uglify?
Note that is works well with *.vue
files.
ClientApp
| - build
| - config
| - src
| - App.Vue // import EscapeKey from '~lib/tools/escape-key';
Lib
| -src
| - tools
| - escape-key.js
Note there is an alias to Lib.
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'@': resolve('src'),
'~lib': path.join(__dirname, '../../lib/src'),
}
},
Please feel free to ask for more details if required.
After changing my babel-loader config, it worked.
{
test: /\.js$/,
loader: 'babel-loader',
include: [path.join(__dirname, '../../Lib/src'), resolve('src'), resolve('test')]
}