ES6 minify / uglify

I’m pretty sure this is a duplicate, but I couldn’t find another already open issue about it.

I’d like to not transpile my es6 code with babel to es5 before uglifying it: I’d rather use a minified es6 version of my codebase.
Is there any uglifier production-ready/webpack-ready for this?

Watching in the meantime:
https://gist.github.com/avdg/43002267f959210a69aa3ec0f21ed751

Author: Fantashit

10 thoughts on “ES6 minify / uglify

  1. I can see two options:

    1. Fork webpack and point uglifyjs dependency to the branch.
    2. Extract the UglifyJs plugin from the project and point that to the branch.

    I’m not actually sure why UglifyJS plugin is at the core level as it could easily be a package of its own. Extra dependency to manage then, though.

  2. @fulls1z3 I don’t quite understand what you are/were trying to do with that fork. There is no need to fork Webpack in order to use the harmony branch; just add "uglify-js": "git://github.com/mishoo/UglifyJS2#harmony" to your project’s package.json, rm -rf node_modules && npm install, and voilà.

  3. @damianobarbati There’s not that much difference, but I think we all should strive for advancing the ecosystem. If we still keep transpiling to ES5 10 years from now on, I think the JavaScript ecosystem has failed miserably.

    And, as we all know, browser manufacturers are a bit slow in optimizing their code, so we shouldn’t really be expecting huge performance benefits in near future (or should we?). But the thing is, if we just keep using the plain-old-es5, the browser manufacturers are not really incentivized to optimize their support for ES5+ features.

  4. I am using webpack 2.5.1 and “uglify-js”: “git://github.com/mishoo/UglifyJS2#harmony”,
    It worked till 8th may 2017.

    Now it fails with the error:

    ERROR in express.js from UglifyJs
    TypeError: Cannot read property 'reset' of undefined
        at filterdFiles.forEach.err (/Library/WebServer/Documents/dvel/waves-provider/api-provider/node_modules/webpack/lib/optimize/UglifyJsPlugin.js:81:20)
        at Array.forEach (native)
        at Compilation.compilation.plugin (/Library/WebServer/Documents/dvel/waves-provider/api-provider/node_modules/webpack/lib/optimize/UglifyJsPlugin.js:40:18)
        at next (/Library/WebServer/Documents/dvel/waves-provider/api-provider/node_modules/tapable/lib/Tapable.js:140:14)
        at Compilation.compilation.plugin (/Library/WebServer/Documents/dvel/waves-provider/api-provider/node_modules/webpack/lib/BannerPlugin.js:67:5)
        at Compilation.applyPluginsAsyncSeries (/Library/WebServer/Documents/dvel/waves-provider/api-provider/node_modules/tapable/lib/Tapable.js:142:13)
        at self.applyPluginsAsync.err (/Library/WebServer/Documents/dvel/waves-provider/api-provider/node_modules/webpack/lib/Compilation.js:635:10)
        at Compilation.applyPluginsAsyncSeries (/Library/WebServer/Documents/dvel/waves-provider/api-provider/node_modules/tapable/lib/Tapable.js:131:46)
        at sealPart2 (/Library/WebServer/Documents/dvel/waves-provider/api-provider/node_modules/webpack/lib/Compilation.js:631:9)
        at Compilation.applyPluginsAsyncSeries (/Library/WebServer/Documents/dvel/waves-provider/api-provider/node_modules/tapable/lib/Tapable.js:131:46)
        at Compilation.seal (/Library/WebServer/Documents/dvel/waves-provider/api-provider/node_modules/webpack/lib/Compilation.js:579:8)
        at /Library/WebServer/Documents/dvel/waves-provider/api-provider/node_modules/webpack/lib/Compiler.js:493:16
        at /Library/WebServer/Documents/dvel/waves-provider/api-provider/node_modules/tapable/lib/Tapable.js:225:11
        at _addModuleChain (/Library/WebServer/Documents/dvel/waves-provider/api-provider/node_modules/webpack/lib/Compilation.js:481:11)
        at processModuleDependencies.err (/Library/WebServer/Documents/dvel/waves-provider/api-provider/node_modules/webpack/lib/Compilation.js:452:13)
        at _combinedTickCallback (internal/process/next_tick.js:67:7)
        at process._tickCallback (internal/process/next_tick.js:98:9)
    

    Does anyone has similar error?

  5. UglifyJS seems to have bumped to a new major version. Try

    "uglify-js": "git://github.com/mishoo/UglifyJS2#harmony-v2.8.22"

  6. Installing "uglifyjs-webpack-plugin": "^1.0.0-beta.2" works for me (with "webpack": "^3.6.0").

    const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
    // ...
    plugins: [
      // expose and write the allowed env vars on the compiled bundle
      new webpack.DefinePlugin({
        'process.env.NODE_ENV': JSON.stringify(env.NODE_ENV)
      }),
      new webpack.LoaderOptionsPlugin({
        minimize: true,
        debug: false
      }),
      new UglifyJSPlugin({
        uglifyOptions: {
          beautify: false,
          ecma: 6,
          compress: true,
          comments: false
        }
      })
    ]

Comments are closed.