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

Add ability to skip files in UglifyJs via user-defined function #560

Merged
merged 2 commits into from
Oct 30, 2014

Conversation

bernii
Copy link
Contributor

@bernii bernii commented Oct 29, 2014

Use case: User has some legacy library that breaks when treated with UglifyJs.
This change gives user a ability to exclude some of the files by conveniently providing custom function (via options) that will decide if a particular file should be skipped.

@sokra
Copy link
Member

sokra commented Oct 30, 2014

Could you use a similar logic like in module.loaders?

A test, include and exclude option, which could be a string, RegExp or array of those.

(defaults to test: /\.js($|\?)/i)

http://webpack.github.io/docs/configuration.html#module-loaders
https://github.com/webpack/core/blob/master/lib/LoadersList.js#L69-L77

@bernii
Copy link
Contributor Author

bernii commented Oct 30, 2014

Great idea @sokra, I've updated the PR. Long term this logic could be extracted and held separate in a filtering module to keep the code DRY.

sokra added a commit that referenced this pull request Oct 30, 2014
Add ability to skip files in UglifyJs via user-defined function
@sokra sokra merged commit e400afb into webpack:master Oct 30, 2014
@snapwich
Copy link

I might be mistaken, but I don't think this code does what this pull-request intended.

Right now it runs the regexp matches as a filter against "files" which is an array of the generated chunks. Shouldn't it run it against the individual required modules? I'm not sure what use there is in telling it to exclude uglifying a whole generated chunk, especially since webpack is usually just generating one chunk.

@bernii
Copy link
Contributor Author

bernii commented Dec 16, 2014

@snapwich sorry for not being clear enough in the PR description. You're right, the change here affects the whole bundle. My use case is that one of the bundles contains a legacy JS file that should not be minified and I want to prevent that file form being uglified. It would be better to exclude just a single file instead of whole chunk but I haven't found a way to do that with the webpack plugin system.

@bestander
Copy link

I've just created a tiny loader for this https://github.com/bestander/uglify-loader
It does not expose uglify API yet and calls uglify-js with default parameters.

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

Successfully merging this pull request may close these issues.

None yet

4 participants