UglifyJS throws unexpected token: keyword (const) with node_modules

后端 未结 7 1849
清歌不尽
清歌不尽 2020-12-13 16:31

A small project I started make use a node module (installed via npm) that declares const variables. Running and testing this project is well, b

相关标签:
7条回答
  • 2020-12-13 17:32

    As ChrisR mentionned, UglifyJS does not support ES6 at all.

    You need to use terser-webpack-plugin for ES6 (webpack@5 will use this plugin for uglification)

    npm install terser-webpack-plugin --save-dev
    

    Then define in your plugins array

    const TerserPlugin = require('terser-webpack-plugin')
    
      new TerserPlugin({
        parallel: true,
        terserOptions: {
          ecma: 6,
        },
      }),
    

    Source

    0 讨论(0)
提交回复
热议问题