Babel 没有将代码从 ES6 编译到 ES5?

时间:2021-07-21 16:41:08

标签: angular webpack babeljs ecmascript-5

我正在尝试在生产环境中运行一个 webpack 项目。

package.json

  "scripts": {
    "start": "yarn run server:dev",
    "compile": "webpack --config config/webpack.production.js --display-error-details",
    "server:dev": "webpack-dev-server -d --config config/webpack.dev.js  --content-base src/ --host 0.0.0.0 --port 9000",
    "postinstall": "typings install"
  }

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "allowSyntheticDefaultImports": true,
    "downlevelIteration": true,
    "lib": ["es6", "dom", "es2017"],
    "module": "commonjs",
    "moduleResolution": "node",

当我运行 npm run compile 时,我收到错误 ERROR in app.js from UglifyJs Unexpected token: name (NgUploaderService) [app.js:31524,6] 我认为这是 ES6->ES5 错误,因此将 babel 合并到 webpack.production 中,但我仍然收到错误。

webpack.production.js

module.exports = webpackMerge(commonConfig, {
    output: {
        path: helpers.root('dist'),
        publicPath: PRODUCTION_HOST,
        filename: '[name].js',
        chunkFilename: '[id].chunk.js'
    },
    devtool: 'hidden-source-map',
    module: {
        loaders: [{
            test: /\.js?$/,
            exclude: /node_modules/,
            loader: 'babel-loader',
            query: {
                presets: ['env']
            }
        }]
    },
    plugins: [
        new UglifyJsPlugin({
            beautify: false,
            output: {
                comments: false
            },
                mangle: {
                screw_ie8: true
            },
            compress: {
                screw_ie8: true,
                warnings: false,
                conditionals: true,
                unused: true,
                comparisons: true,
                sequences: true,
                dead_code: true,
                evaluate: true,
                if_return: true,
                join_vars: true,
                negate_iife: false // we need this for lazy v8
            }
        })
    ]
});

所以,当我运行 serve -s build 时,我得到:enter image description here

0 个答案:

没有答案
相关问题