我正在使用webpack并希望部署我的网站。如果我压缩和捆绑JavaScript代码,我会遇到这个错误:
解析错误:意外的标记:
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 配置文件:
Note in bundled code the keyword export
is removed. In development, there are no errors thrown. Here you could find my configuration file of 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
更改为false,就不会出现错误,如果为true,则会出现上述错误。我的问题是:我可以在Webpack中启用ES6吗?