我正在使用webpack并希望部署我的网站。如果我再压缩和捆绑我的JavaScript代码,我得到这个错误:如何使用Webpack来缩小ES6代码?
Parse error: Unexpected token: name (
Button
)
这里是我的非绑定代码:捆绑代码
'use strict';
export class Button { // <-- Error happens on this line
constructor(translate, rotate, text, textscale = 1) {
this.position = translate;
this.rotation = rotate;
this.text = text;
this.textscale = textscale;
}
}
注意关键字export
被删除。在开发过程中,不会出现任何错误。在这里,你可以找到的WebPack我的配置文件:
var webpack = require('webpack');
var PROD = true;
module.exports = {
entry: "./js/entry.js",
output: {
path: __dirname,
filename: PROD ? 'bundle.min.js' : 'bundle.js'
},
module: {
loaders: [
{
test: /\.css$/,
loader: "style-loader!css-loader"
}
]
},
plugins: PROD ? [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
output: {
comments: false,
},
})
] : []
};
如果我改变PROD
为假,我没有错误,如果是真的,我从上面得到了错误。我的问题是我可以在Webpack中启用ES6吗?
我假设你不想transpile与巴贝尔你的代码? –
https://github.com/webpack-contrib/babili-webpack-plugin和https://www.npmjs.com/package/uglify-es浮现在脑海中(但我不知道如何整合后者与的WebPack)。 –