Skip to content

Update noParse docs #4908

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

Closed
wants to merge 1 commit into from
Closed

Update noParse docs #4908

wants to merge 1 commit into from

Conversation

jakub-g
Copy link
Contributor

@jakub-g jakub-g commented Apr 22, 2021

  1. Warn about [\\/] for portability (/ does not match on Windows)
  2. Document noParse x require.

I had an issue like described with 3rd-party lib (webpack 4 was expanding require('os'), require('http') with shims).

An alternative way to prevent expansion of require-s would be defining externals, one by one, but I think noParse is a better solution - I just tell webpack to bundle the file as-is, instead of going through all the code and all those requires.

externals: {
    os: 'var {}',
    http: 'var {}',
    https: 'var {}',
},

@vercel
Copy link

vercel bot commented Apr 22, 2021

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/DTDQXG3UvFbUuzitWWnjEThpB2A6
✅ Preview: https://webpack-js-org-git-fork-jakub-g-patch-4-webpack-docs.vercel.app

@chenxsan
Copy link
Member

Can you share the 3rd-party lib you mentioned so I can check? In addition, I noticed you mentioned webpack 4, are those changes for webpack 4 only? We have a https://github.com/webpack/webpack.js.org/tree/webpack-4 branch for webpack 4 documentation, and the master branch is kept for webpack 5.

@@ -194,13 +194,18 @@ The `'relative'` value for `module.parser.javascript.url` is available since web

Prevent webpack from parsing any files matching the given regular expression(s). Ignored files **should not** have calls to `import`, `require`, `define` or any other importing mechanism. This can boost build performance when ignoring large libraries.

`noParse` can be also used as a way to deliberately prevent expansion of all `import`, `require`, `define` etc. calls, if you're sure those calls are unreachable at runtime.
For example, when building a project for browser target, and using a third-party library that was prebuilt as a dual browser/nodejs lib, and requires some nodejs built-ins, like `require('os')`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
For example, when building a project for browser target, and using a third-party library that was prebuilt as a dual browser/nodejs lib, and requires some nodejs built-ins, like `require('os')`.
For example, when building a project for `'browser'` [target](/configuration/target/) and using a third-party library that was prebuilt for both browser and Node.js and it requires Node.js built-ins e.g. `require('os')`.

@@ -194,13 +194,18 @@ The `'relative'` value for `module.parser.javascript.url` is available since web

Prevent webpack from parsing any files matching the given regular expression(s). Ignored files **should not** have calls to `import`, `require`, `define` or any other importing mechanism. This can boost build performance when ignoring large libraries.

`noParse` can be also used as a way to deliberately prevent expansion of all `import`, `require`, `define` etc. calls, if you're sure those calls are unreachable at runtime.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
`noParse` can be also used as a way to deliberately prevent expansion of all `import`, `require`, `define` etc. calls, if you're sure those calls are unreachable at runtime.
`noParse` can be also used as a way to deliberately prevent expansion of all `import`, `require`, `define` etc. calls for cases when those calls are unreachable at runtime.

`noParse` can be also used as a way to deliberately prevent expansion of all `import`, `require`, `define` etc. calls, if you're sure those calls are unreachable at runtime.
For example, when building a project for browser target, and using a third-party library that was prebuilt as a dual browser/nodejs lib, and requires some nodejs built-ins, like `require('os')`.

Note the need to use `[\\/]` in regex to match `\` on Windows and `/` on Mac/Linux.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Note the need to use `[\\/]` in regex to match `\` on Windows and `/` on Mac/Linux.
T> You may need to use `[\\/]` in regex to match `\` on Windows and `/` on Mac/Linux.

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

Successfully merging this pull request may close these issues.

3 participants