-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
docs(configuration): update node page for webpack 5 #4078
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
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/webpack-docs/webpack-js-org/m4qpht8fd |
--- | ||
|
||
The following Node.js options configure whether to polyfill or mock certain [Node.js globals](https://nodejs.org/docs/latest/api/globals.html) and modules. This allows code originally written for the Node.js environment to run in other environments like the browser. | ||
The following Node.js options configure whether to polyfill or mock certain [Node.js globals](https://nodejs.org/docs/latest/api/globals.html). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node
option only defines three Node.js globals now https://github.com/webpack/webpack/blob/60f7ce301df553d8ab0276ba2838ddb60ead1c94/declarations/WebpackOptions.d.ts#L1365, so information related to modules
is removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows code originally written for the Node.js environment to run in other environments like the browser.
was removed as it's not true anymore, we have to polyfill Node.js modules like fs
etc. as well, which is described in resolve.fallback
section https://github.com/webpack/webpack/blob/master/lib/ModuleNotFoundError.js#L67.
|
||
This feature is provided by webpack's internal [`NodeStuffPlugin`](https://github.com/webpack/webpack/blob/master/lib/NodeStuffPlugin.js) plugin. If the target is "web" (default) or "webworker", the [`NodeSourcePlugin`](https://github.com/webpack/webpack/blob/master/lib/node/NodeSourcePlugin.js) plugin is also activated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NodeSourcePlugin
is empty now https://github.com/webpack/webpack/blob/master/lib/node/NodeSourcePlugin.js, so no need to keep.
|
||
T> If you are using a module which needs global variables in it, use `ProvidePlugin` instead of `global`. | ||
|
||
These are the defaults: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty
was removed in webpack 5 https://github.com/webpack/webpack/blob/60f7ce301df553d8ab0276ba2838ddb60ead1c94/declarations/WebpackOptions.d.ts#L1369
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed the whole part as I think they're already listed below, there's no need to duplicate them here. But I can revert it if you think it's better to keep.
- `'mock'`: The fixed value `'/'`. | ||
- `'eval-only'` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works same as false
in my test, but I'm not sure of this value as there's no description in webpack repository.
|
||
Defaults to `false` for [targets](/configuration/target/) `node`, `async-node` and `electron-main`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove this? Is there a summary of TARGETS
I'm missing, or...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember the specific reason. There're more than three targets having node.global
set to false
, which could be the reason I removed this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deleted info is outdated, indeed, but why not update it, instead of deleting it? How can I find out what it defaults to without digging into the code?
I'm concerned about this because I actually had an old todo, about improving this page, and by the time I got around to it, somebody already added the defaults, and when I went to look who did it, out of curiosity, I find that it got deleted 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pr welcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't encourage me to contribute in this particular case. As it stands, it'll just get deleted a few months later again because of being slightly inaccurate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's difficult to align with all changes happening in webpack core project. There will always some stale contents.
The contents for
node
page changed a lot in webpack 5, so I refactor some.For the sake of review, I've added some comments too.
Preview URL: https://webpack-js-org-git-bugfix-update-node.webpack-docs.vercel.app/configuration/node/