这是编译后我的脚本的一部分的快照:
我不明白为什么它不将 new.target
转换为 this.constructor
?
示例:
class IList {
constructor() {
console.log('compare using new.target:', new.target === IList);
console.log('compare using this.constructor:', this.constructor === IList);
}
}
new IList();
我希望它这样做,因为我可以在不支持 es6 的浏览器中使用 this.constructor
,而 new.target
需要。
我应该向 webpack 团队报告吗?
更新:
webpack.config.js
:
let webpack = require('webpack'),
path = require('path'),
BabiliPlugin = require("babili-webpack-plugin");
module.exports = {
entry: {
'site': './assets/js/site',
'site.min': './assets/js/site'
},
output: {
publicPath: '/js/',
path: path.join(__dirname, '/wwwroot/js/'),
filename: '[name].js'
},
module: {
loaders: [
{
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015', 'stage-1']
}
}
]
},
plugins: [
new BabiliPlugin({}, {
test: /\.min\.js$/
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
]
};
最佳答案
看来这个问题在 Babel 7 中已得到解决。请参阅 https://github.com/babel/babel/pull/5906
似乎它包含在预发布版本中:https://github.com/babel/babel/releases
关于javascript - webpack 编译器根本不会将 es6 语法转换为旧版本的语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45560268/