【发布时间】:2018-01-15 13:09:35
【问题描述】:
这是我的脚本编译后的一部分快照:
我不明白为什么它不将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 而 new.target 需要的浏览器中使用 this.constructor。
我应该向 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'
})
]
};
【问题讨论】:
-
Webpack 可以使用 Babel-package 将 ES6 转换为 ES5 代码。您能否提供有关您的设置(~packages)的更多信息?
-
@Jorg 不是。我脚本中的几乎 es6 语法已成功转换。除了
new.target -
@Alan 那是因为你的 Babel 版本doesn't yet support transpiling
new.target。其余的按预期工作。 -
@Alan 这意味着您有 2 年的时间来提交拉取请求 :-) 维护人员很忙,总是欢迎帮助 - 这是一个社区项目。
new.target不是优先事项。
标签: javascript webpack ecmascript-6