Skip to content

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

Merged
merged 2 commits into from
Nov 19, 2020

Conversation

chenxsan
Copy link
Member

@chenxsan chenxsan commented Oct 18, 2020

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/

@vercel
Copy link

vercel bot commented Oct 18, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/webpack-docs/webpack-js-org/m4qpht8fd
✅ Preview: https://webpack-js-org-git-bugfix-update-node.webpack-docs.vercel.app

---

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).
Copy link
Member Author

@chenxsan chenxsan Oct 18, 2020

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.

Copy link
Member Author

@chenxsan chenxsan Oct 18, 2020

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.
Copy link
Member Author

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:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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.

@chenxsan chenxsan marked this pull request as ready for review October 18, 2020 04:29
- `'mock'`: The fixed value `'/'`.
- `'eval-only'`
Copy link
Member Author

@chenxsan chenxsan Oct 18, 2020

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.

@chenxsan chenxsan changed the title docs(configuration): update for webpack 5 docs(configuration): update node page for webpack 5 Oct 18, 2020
@chenxsan chenxsan closed this Nov 16, 2020
@chenxsan chenxsan reopened this Nov 16, 2020
@chenxsan chenxsan merged commit c142e75 into webpack:master Nov 19, 2020

Defaults to `false` for [targets](/configuration/target/) `node`, `async-node` and `electron-main`.
Copy link

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...?

Copy link
Member Author

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.

Copy link

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 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pr welcome.

Copy link

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.

Copy link
Member Author

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.

@chenxsan chenxsan deleted the bugfix/update-node branch February 18, 2021 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants