UglifyJS breaks with new module syntax

I’m submitting a bug report

Webpack version:
2.1.0-beta.25

Please tell us about your environment:
Linux x64

Current behavior:
I took a working project using the old module syntax (loaders/loader/query) and replaced it with the new syntax (rules/use/options) and I get the following error:
SyntaxError: Unexpected character '‘ [main.min.js:5429,52]`
Note that replacing the syntax (only those three words) is the ONLY change made. Using the old syntax does not yield this error.

Expected/desired behavior:
The bundle would be generated and minified as it is using the old syntax.

  • Language: [ES6/7 | ES5]

Author: Fantashit

2 thoughts on “UglifyJS breaks with new module syntax

  1. UglifyJS does not support ES2015+ syntax. You must migrate to the latest version of UglifyJSPlugin in order to minify your code.

    First you need to add (or update) the plugin dependency:

    npm install -D "uglifyjs-webpack-plugin@^1.1.0"
    

    Then require the plugin:

      const webpack = require("webpack")
    + const UglifyJSPlugin = require("uglifyjs-webpack-plugin")

    And update your build configuration:

      plugins: [
    -   new webpack.optimize.UglifyJSPlugin({
    +   new UglifyJSPlugin({
          sourceMap: true,
    -     compress: {
    -       warnings: false
    +     uglifyOptions: {
    +       compress: {
    +         warnings: false
    +       }
          }
       }),
      ]

Comments are closed.