Static GitHub Issues

[385] Use BabiliPlugin() instead of UglifyJs()

prev: Flash of content (foc) when not in dev mode
next: How to pass request.currentUser to context.req in Nuxt framework

version

  • nuxt 0.9.9
  • element-ui 1.2.3

Error Reason

ERROR in 0.console.js from UglifyJs
Unexpected token name «i», expected punc «;» [0.console.js:2128,11]

So I look up the source file 0.console.js, I found the source file is element-ui/src/utils/merge.js

export default function(target) {
  for (let i = 1, j = arguments.length; i < j; i++) {
    let source = arguments[i] || {};
    for (let prop in source) {
      if (source.hasOwnProperty(prop)) {
        let value = source[prop];
        if (value !== undefined) {
          target[prop] = value;
        }
      }
    }
  }

  return target;
};

I found the let keyword. But webpack.optimize.UglifyJsPlugin unsupport ES6 grammar default.

My solution change UglifyJsPlugin plugin

const BabiliPlugin = require('babili-webpack-plugin')
module.exports = {
  build: {
    extend (config, {dev}) {
      if(!dev) {
        config.plugins = config.plugins.filter((plugin) => plugin.constructor.name !== 'UglifyJsPlugin')
        config.plugins.push(new BabiliPlugin())
      }
    }
  }
}

@Atinux Do you have any better ideas?

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This feature request is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c335">#c335</a>)</em></sub></div>