javascript - webpack 编译器根本不会将 es6 语法转换为旧版本的语法

标签 javascript webpack ecmascript-6

这是编译后我的脚本的一部分的快照:

1

我不明白为什么它不将 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/

相关文章:

javascript - 使用 Mix 在 Laravel 中未检测到 VueJs

javascript - 422(无法处理的实体)使用 Rails 进行 POST

vue.js - 视觉 : How do you add E2E tests after not including them in initial webpack template?

debugging - IntelliJ IDEA TypeScript/Webpack 调试仅适用于 JavaScript 断点

node.js - co node.js 库的用途是什么?

javascript - 使用与 ES6/7 的变量名称相同的键从变量创建对象

Javascript动态向对象添加值

javascript - 需要有关 jquery 选择器的帮助

angular - 在特定的 Docker 容器环境中配置 Angular 2 Webpack App

javascript - 我可以将 .map 数组转换为带双引号的逗号分隔数组吗?