我正在使用 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配置文件:
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 吗?