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

Setting output.globalObject breaks parsed + gzip #288

Open
ntucker opened this issue Jun 23, 2019 · 11 comments
Open

Setting output.globalObject breaks parsed + gzip #288

ntucker opened this issue Jun 23, 2019 · 11 comments

Comments

@ntucker
Copy link

ntucker commented Jun 23, 2019

Issue description

config.output.globalObject = "(typeof self !== 'undefined' ? self : this)"

Breaks parsed + gzip sizes. Removing it fixed them.

Technical info

  • Webpack Bundle Analyzer version: 3.3.2
  • Webpack version: 4.35.0
  • Node.js version: 11.10.0
  • npm/yarn version: 6.7.0
  • OS: mac os x; windows

Expected Behavior

Gzip and parsed should contain data bout more than just the output files - the modules inside them as well.

Actual Behavior

Only stats includes all modules. Gzip and parsed just show large blocks for each bundle piece (output file)

Code

My default:

config.output.globalObject = "(typeof self !== 'undefined' ? self : this)"

When I analyze:

delete config.output.globalObject;
@valscion
Copy link
Member

valscion commented Jul 2, 2019

Sorry, I don't quite follow you. Is the piece of code you are referring to some part of webpack-bundle-analyzer or your own code?

@ntucker
Copy link
Author

ntucker commented Jul 2, 2019

the config setting lines are setting the webpack config. This issue describes what happens to any bundle when the configuration is as such.

@valscion
Copy link
Member

valscion commented Jul 3, 2019

I'm having a hard time figuring out what is exactly what's happening here. Can you create a small reproduction repository to show what's happening?

I'm afraid I can't help you otherwise

@ntucker
Copy link
Author

ntucker commented Jul 3, 2019

https://webpack.js.org/configuration/output/#outputglobalobject This is the webpack configuration. You can use with any project. Just set that to "(typeof self !== 'undefined' ? self : this)" and add bundle analyzer

@valscion
Copy link
Member

valscion commented Jul 3, 2019

But why would you use self or this in there? Do you mean 'this' instead of this?

@ntucker
Copy link
Author

ntucker commented Jul 3, 2019

@valscion
Copy link
Member

valscion commented Jul 4, 2019

Yes but the webpack configuration expects you to put a string in there, not an object, unless I misunderstand the instructions in https://webpack.js.org/configuration/output/#outputglobalobject documentation you linked?

@ntucker
Copy link
Author

ntucker commented Jul 5, 2019

"(typeof self !== 'undefined' ? self : this)" is a string literal. In javascript this is signified by the quotation marks surrounding the other characters.

@valscion
Copy link
Member

valscion commented Jul 5, 2019

But it won't be evaluated as JS unless you put it in backticks? It means your string will be exactly what you write, not either 'self' or 'this'.

Was this what you have, or would need?

config.output.globalObject = (typeof self !== 'undefined' ? 'self' : 'this')

This code will not do any conditionals:

config.output.globalObject = "(typeof self !== 'undefined' ? self : this)"

The result will be only the raw string "(typeof self !== 'undefined' ? self : this)" as is, not self or this.

@th0r
Copy link
Collaborator

th0r commented Jul 5, 2019

But it won't be evaluated as JS unless you put it in backticks?

This string is inserted in the generated code as-is - it should not be evaluated at compile time.

E.g. imagine this bundle template:

var global = {{ config.globalObject }};

Then resulting bundle will be:

var global = (typeof self !== 'undefined' ? self : this);

@valscion
Copy link
Member

valscion commented Jul 5, 2019

Oh wow, that wasn't obvious at all from the webpack documentation. Thanks for explaining.

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

No branches or pull requests

3 participants