Skip to content

docs(configuration): document webpackIgnore for commonjs #4476

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ T> Note that `webpackInclude` and `webpackExclude` options do not interfere with
The goal of CommonJS is to specify an ecosystem for JavaScript outside the browser. The following CommonJS methods are supported by webpack:


### `require`
### require

```typescript
require(dependency: String);
Expand All @@ -185,9 +185,12 @@ var $ = require('jquery');
var myModule = require('my-module');
```

It's possible to enable magic comments for `require` as well, see [`module.parser.javascript.commonjsMagicComments`](/configuration/module/#moduleparserjavascriptcommonjsmagiccomments) for more.

W> Using it asynchronously may not have the expected effect.



### `require.resolve`

```typescript
Expand Down
48 changes: 47 additions & 1 deletion src/content/configuration/module.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = {
};
```

## `module.parser`
## module.parser

<Badge text='5.12.0+' />

Expand Down Expand Up @@ -107,6 +107,51 @@ module.exports = {
};
```


### module.parser.javascript

Configure options for JavaScript parser.

```js
module.exports = {
module: {
parser: {
javascript: {
// ...
commonjsMagicComments: true,
},
},
},
};
```

It's allowed to configure those options in [`Rule.parser`](/configuration/module/#ruleparser) as well to target specific modules.

#### module.parser.javascript.commonjsMagicComments

Enable [magic comments](/api/module-methods/#magic-comments) support for CommonJS.

- Type: `boolean`
Copy link
Member

Choose a reason for hiding this comment

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

We usually put the types below the title, Why this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's explicit, and I believe it's much readable. Moreover, with explicit format we could possibly customize those complex types with <details> element in the future.

- Available: 5.17.0+
- Example:
```js
module.exports = {
module: {
parser: {
javascript: {
commonjsMagicComments: true,
},
}
},
};
```

Note that only `webpackIgnore` comment is supported at the moment:

```js
const x = require(/* webpackIgnore: true */ 'x');
```

## `module.noParse`

`RegExp` `[RegExp]` `function(resource)` `string` `[string]`
Expand Down Expand Up @@ -421,6 +466,7 @@ module.exports = {
browserify: false, // disable special handling of Browserify bundles
requireJs: false, // disable requirejs.*
node: false, // disable __dirname, __filename, module, require.extensions, require.main, etc.
commonjsMagicComments: false, // disable magic comments support for CommonJS
node: {...}, // reconfigure [node](/configuration/node) layer on module level
worker: ["default from web-worker", "..."] // Customize the WebWorker handling for javascript files, "..." refers to the defaults.
}
Expand Down