Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UglifyJS issues #6

Closed
iongion opened this issue Jun 21, 2017 · 5 comments
Closed

UglifyJS issues #6

iongion opened this issue Jun 21, 2017 · 5 comments
Labels

Comments

@iongion
Copy link

iongion commented Jun 21, 2017

I am using fs-extra which uses universalify, now there is a problem when using uglifyjs as it does not know arrow functions, can you change the module not to use arrow functions ?

The scenario is this:

I deploy NodeJS server side apps, bundled in a single file(executing in AWS lambda env).
As you know, webpack usually has an ignore option when transpiling and in the most common cases node_modules is what is ignored.

Now, after webpack transpiles the code it will post processes it using UglifyJS and there, UglifyJS gets stuck as it cannot minify arrow functions:

'use strict'

exports.fromCallback = function (fn) {
  return Object.defineProperty(function () {
    if (typeof arguments[arguments.length - 1] === 'function') fn.apply(this, arguments)
    else {
      return new Promise(function (resolve, reject) {
        arguments[arguments.length] = function(err, res) {
          if (err) return reject(err)
          resolve(res)
        }
        arguments.length++
        fn.apply(this, arguments)
      })
    }
  }, 'name', { value: fn.name })
}

exports.fromPromise = function (fn) {
  return Object.defineProperty(function () {
    const cb = arguments[arguments.length - 1]
    if (typeof cb !== 'function') return fn.apply(this, arguments)
    else fn.apply(this, arguments).then(function(r) {
      cb(null, r);
    }).catch(cb)
  }, 'name', { value: fn.name })
}
@RyanZim
Copy link
Owner

RyanZim commented Jun 21, 2017

fs-extra (and universalify) only support Node 4+ which supports arrow functions just fine. fs-extra uses them as well. We're not going to revert just to support outdated tooling.

You need to use the es branch of UglifyJS: https://www.npmjs.com/package/uglify-es

CC: @jprichardson

@jprichardson
Copy link

jprichardson commented Jun 21, 2017

@iongion I don't understand why you'd uglify your own code in a server environment.

@vinaynb
Copy link
Contributor

vinaynb commented Jun 18, 2018

@jprichardson any tips on what if the use case is using this package in a electron app after uglifying it ?

@vinaynb
Copy link
Contributor

vinaynb commented Jun 18, 2018

@RyanZim i understand your point of not reverting the code but can we just add a engines property to package.json explicitly declaring minimum node version required by plugin. Doing this will help people like me who can use babel-engine-plugin and transpile such modules using babel.

@RyanZim
Copy link
Owner

RyanZim commented Jun 18, 2018

The real solution is to use https://www.npmjs.com/package/uglify-es. That said, I'm not opposed to adding engines to the package.json. PR welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants