添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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 [Docs] output.globalObject indicates default value of 'window' - but that doesn't seem to be the default value #4924 [Docs] output.globalObject indicates default value of 'window' - but that doesn't seem to be the default value #4924 Nantris opened this issue Apr 29, 2021 · 3 comments · Fixed by #6025

What is the current behavior?
Our build fails to load on iOS with no globalObject key defined in our config, but when we define globalObject: 'window' it runs correctly.

Our config is otherwise like this:

output: {
  path: path.join(__dirname, './dist'),
  filename: 'index.js',
  libraryTarget: 'umd',
  // globalObject: 'window',
  publicPath: '/dist/',
  umdNamedDefine: true,

If the current behavior is a bug, please provide the steps to reproduce.
Not sure how to answer this.

What is the expected behavior?
Explicitly defining globalObject: 'window' should have identical behavior as failing to declare the globalObject key at all.

Other relevant information:
webpack version: 5.31.1
Node.js version: 12.21.0
Operating System: Windows 7

So our situation is working now a-okay, but if I hadn't tried this seemingly silly idea, I don't know how many hours I would have spent wondering what could possibly be wrong. So I'm hoping that someone knows what the real default value is and hopefully we can get the docs fixed quickly and potentially save someone else a lot of head scratching.

Thanks for your reply @alexander-akait. I see that the default is 'self', but that it's not quite that simple, so it's not clear to me what the docs should say, but if you can clarify I'd be happy to submit a PR.

I found these additional details related to what you mentioned but they didn't clarify it enough for me to know what the docs should say for output.globalObject.

The return value of your entry point will be assigned to the global object using the output.library.name value. Depending on the target value, the global object could change respectively, e.g., self, global or globalThis.