-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
feat(CommonJsPlugin): magic comment to ignore require calls #11316
Conversation
|
For maintainers only:
|
Note: It would be great if this could be back-ported to 4.x since AFAIK 5 is not out/stable yet. |
Will take care of the backport 👍 |
Looks good. I wonder how this affects performance considering there are a lot more |
@sokra It depends mostly on the performance characteristics of the comment parsing in the edge case when there are no comments to be parsed in the require() call (which is what will happen 99.9% of the time). |
Yeah actually the Could you improve it by using binary search? The comments array should be sorted anyway... |
@sokra Would something like this be okay? => 04d6b0f I left it in a separate commit because it doesn't really have anything to do with the magic comment feature itself, but happy to squash of course, just let me know. EDIT: Updated commit link after force push |
Hi @petermetz. Just a little hint from a friendly bot about the best practice when submitting pull requests:
You don't have to change it for this PR, just make sure to follow this hint the next time you submit a PR. |
@petermetz Thanks for your update. I labeled the Pull Request so reviewers will review it again. @sokra Please review the new changes. |
5fa8e15
to
3790c0b
Compare
Depends on webpack/webpack#11316 This has no real effect until the PR above is merged and releaed on Webpack (and then we upgrade to that release for the builds) How this fix works is explained in the linked PR in greater detail. Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
Depends on webpack/webpack#11316 This has no real effect until the PR above is merged and releaed on Webpack (and then we upgrade to that release for the builds) How this fix works is explained in the linked PR in greater detail. Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
Depends on webpack/webpack#11316 This has no real effect until the PR above is merged and releaed on Webpack (and then we upgrade to that release for the builds) How this fix works is explained in the linked PR in greater detail. Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
@petermetz Sorry for delay, can you rebase? |
A partial port of the same magic comments that are supported for import() calls already via this commit: webpack@f65e9da Signed-off-by: Peter Somogyvari <peter.metz@unarin.com>
Signed-off-by: Peter Somogyvari <peter.metz@unarin.com>
@alexander-akait No worries at all. I did the rebase just now, enjoy! |
move javascript related options from 'module' to 'module.parser.javascript'
Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. |
Thanks |
I've created an issue to document this in webpack/webpack.js.org. |
A partial port of the same magic comments that are supported
for import() calls already via this commit:
f65e9da
Fixes #11311
Signed-off-by: Peter Somogyvari peter.metz@unarin.com
Motivation is in the issue comments that I linked above. Bottom line is that I'm using Typescript+Webpack+NodeJS and the import() calls get transpiled into require so the import ignore feature doesn't work for me I need the same for require() calls.
What kind of change does this PR introduce?
feature
Did you add tests for your changes?
Yes.
Does this PR introduce a breaking change?
Not that I'm aware of. It's a new feature.
What needs to be documented once your changes are merged?
You can enable magic comment for CommonJs with
module.parser.javascript.commonjsMagicComments: true
and inRule.parser.commonjsMagicComments: true
.With that enabled you can use the
webpackIgnore: true
magic comment for require calls as well: https://webpack.js.org/api/module-methods/#commonjsSome configuration options has been moved to parser objects as well:
module.{expr|wrapped|unknown}Context{Request|RegExp|Recursive|Critical}
module.strictExportPresence
module.strictThisContextOnImports
module.parser.javascript.xxx
resp.Rule.parser.xxx
module.parser.[module-type]
are merged withRule.parser
. The same for the generator options./
the base module type options are also merged. e.g. forjavascript/esm
:module.parser.javascript
+module.parser["javascript/esm"]
+Rule.parser
(could be multiple, if multiple rules match).