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

ModuleConcatenationPlugin bailout because of undefined injected global #8152

Closed
ludekstepan opened this issue Oct 6, 2018 · 4 comments
Closed

Comments

@ludekstepan
Copy link

Bug report

What is the current behavior?

The ModuleConcatenationPlugin fails to hoist modules that use a global variable even when the global variable is undefined in the target environment.

The example is process, __dirname and other variables from Module Variables

Steps to reproduce.

Please see a gist: https://gist.github.com/ludekstepan/368d5f56afc195e473a6a9d897a5e164

When compiled, the webpack outputs:

[./index.js] 64 bytes {0} [built]
    ModuleConcatenation bailout: Module is an entry point
[./some-dep.js] 98 bytes {0} [built]
    ModuleConcatenation bailout: Module uses injected variables (__dirname)

And the compiled dist/main.js contains two modules:

If I change the__dirname in the dependency module to some other undefined global (like: __foo), the concatenation works as expected.

I want to optimize for size and performance as much as possible, and the concrete application that causes me trouble is: use of process in @most/scheduler

What is the expected behavior?

I expect the ModuleConcatenationPlugin to consider only global variables specific to the target environment.

Other relevant information:
webpack version: 4.20.2

@sokra
Copy link
Member

sokra commented Oct 7, 2018

webpack <= 4 doesn't support concatenation of injected variables. webpack 5 does support it.

@ludekstepan
Copy link
Author

Wow! I've just tried the Webpack 5 and the module got concatenated. However, Webpack included some process shim in the output and that's not something that I want. Is it some new feature? Can I turn it off?

@sokra
Copy link
Member

sokra commented Oct 8, 2018

This is not new. node.process: false should disable it. node: false should disable all node polyfills.

@ludekstepan
Copy link
Author

Thank you very much for reply! I'm closing this issue as this feature will be coming in Webpack 5.

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

No branches or pull requests

2 participants