this code:
https://github.com/mishoo/UglifyJS2/blob/master/tools/node.js#L18
will trigger a warning in webpack:
../~/uglify-js/tools/node.js
24:11-32 Critical dependency: the request of a dependency is an expression
at RequireResolveContextDependency.getWarnings (/Users/others/wishlist/client/wishlist-client/node_modules/webpack/lib/dependencies/RequireResolveContextDependency.js:27:4)
at Compilation.reportDependencyErrorsAndWarnings (/Users/others/wishlist/client/wishlist-client/node_modules/webpack/lib/Compilation.js:672:24)
at Compilation.finish (/Users/others/wishlist/client/wishlist-client/node_modules/webpack/lib/Compilation.js:535:9)
at /Users/others/wishlist/client/wishlist-client/node_modules/webpack/lib/Compiler.js:491:16
at /Users/others/wishlist/client/wishlist-client/node_modules/webpack/node_modules/tapable/lib/Tapable.js:225:11
at _addModuleChain (/Users/others/wishlist/client/wishlist-client/node_modules/webpack/lib/Compilation.js:481:11)
at processModuleDependencies.err (/Users/others/wishlist/client/wishlist-client/node_modules/webpack/lib/Compilation.js:452:13)
at _combinedTickCallback (internal/process/next_tick.js:95:7)
at process._tickCallback (internal/process/next_tick.js:161:9)
The point here is that from that point webpack is unable to optimize the import and you endup with the whole js in your final bundle.
The point here is that from that point webpack is unable to optimize the import and you endup with the whole js in your final bundle.
That's by design.
I see that you import all the libs at that point.
Now what about the warning?
instead of the map function, you could just require each js and the warning will be gone.
If you need to parse & embed uglify-js, consider using the version generated by --self
I need to see this warnig go away. that is all.
Instead of using the require function in your code passing a variable, you could simply:
require.resolve("../lib/utils.js"),
require.resolve("../lib/ast.js"),
...
@rolele thanks for the clarification, though I still don't see the point. We can't keep making cosmetic changes whenever a third party tool decides to emit a new warning.
I agree @alexlamsl.
Now we are talking about webpack which is one of the mainstream tool to build js today.
Look at what the core-team of webpack is saying about this issue here:
https://github.com/webpack/webpack/issues/196
This is a bad practice for the right reasons and can be easily solved in most cases (your case included)
I also ran into this problem. As highlighted above, the fix is simple. Please see #3432
Most helpful comment
I agree @alexlamsl.
Now we are talking about webpack which is one of the mainstream tool to build js today.
Look at what the core-team of webpack is saying about this issue here:
https://github.com/webpack/webpack/issues/196
This is a bad practice for the right reasons and can be easily solved in most cases (your case included)