UglifyJS.minify undefined in --self build

Created on 21 Jul 2016  路  9Comments  路  Source: mishoo/UglifyJS

After building uglifyjs --self from master, I call UglifyJS.minify and get an exception that minify is undefined.

I was expecting to have it defined as a function, like parse in this test:

https://github.com/mishoo/UglifyJS2/blob/debc525fa117438d4971df3790f9f476fed65858/test/mocha/cli.js#L17
But if I try to call WrappedUglifyJS.minify("var a = 3;", {fromString: true});, it seems minify is undefined.

Note: I get the same result using only the --self flag.

Not sure if this is a bug or a misunderstanding on my end about --self (and if so, is there a workaround ?) since this seems to have been the case for a few versions back.

enhancement

All 9 comments

Can you identify which version _did_ export minify()?

As far as I can tell, it never was exposed via the --self build as it's contained in tools/node.js which isn't included.

Thanks I understand, it has never been exposed.

So, only the lib/* files are exposed, correct ?

If I wanted to have a minify function similar to the one in tools/node.js but compatible with a browser environment I would have to write it, correct ?

Right now everything in FILES (tools/node.js:10) is exported.

.minify() _could_ be exposed but uses some logic that's only applicable on cli (like reading property mangle name cache). This definitely is something spending some time on.

I think the intention of the --self bundle was to only have in-memory operations so that the resultant uglify bundle could work in any environment - including browsers. .minify() has file operations that must be run in node, reducing its portability.

@kzc There could be aminify() function that does not have file operations (supports only {fromString: true}). What do you think?

This would require some rewrite from someone who has the time to invest in things like this.

That someone could be me.
I am more concerned about the interest to have it merged here, which the previous comment seemed to imply.

@nha Any PR would be reviewed and considered.

Just avoid any Node.JS specific functionality in the --self implementation of minify() - i.e., no Buffer, require()s, etc. Try to retain API compatibility with the existing minify() implementation where possible, and not conflict with it for CLI use.

Prototype in #1366

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kzc picture kzc  路  3Comments

GrosSacASac picture GrosSacASac  路  3Comments

alexlamsl picture alexlamsl  路  5Comments

lhtdesignde picture lhtdesignde  路  3Comments

buu700 picture buu700  路  5Comments