Skip to content

Document webpack change: feat(CommonJsPlugin): magic comment to ignore require calls #4470

Closed
@webpack-bot

Description

@webpack-bot

A pull request by @petermetz was merged and maintainers requested a documentation change.

See pull request: webpack/webpack#11316


A partial port of the same magic comments that are supported
for import() calls already via this commit:
webpack/webpack@f65e9da

Fixes webpack/webpack#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 in Rule.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/#commonjs

Some configuration options has been moved to parser objects as well:

  • module.{expr|wrapped|unknown}Context{Request|RegExp|Recursive|Critical}
  • module.strictExportPresence
  • module.strictThisContextOnImports
  • All have been moved to module.parser.javascript.xxx resp. Rule.parser.xxx
  • If that's not already in the docs: To get the parser options of a module the options in module.parser.[module-type] are merged with Rule.parser. The same for the generator options.
    • If the module type contains / the base module type options are also merged. e.g. for javascript/esm: module.parser.javascript + module.parser["javascript/esm"] + Rule.parser (could be multiple, if multiple rules match).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions