You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds [magic coments](https://webpack.js.org/api/module-methods/#magic-comments) to your dynamic `import()` statements.
3
+
Keep your source code clean, add [magic coments](https://webpack.js.org/api/module-methods/#magic-comments) to your dynamic `import()` statements at build time.
4
4
5
5
NOTE: **This loader ignores dynamic imports that already include comments of any kind**.
6
6
@@ -16,6 +16,26 @@ Magic comments supported:
16
16
17
17
First `npm install magic-comments-loader`.
18
18
19
+
Try *not* to have dynamic `import()` statements behind [comments](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#comments). **It is better to remove unused code in production**.
20
+
If you must, e.g. your comment is referencing usage of dynamic imports, then these styles are ok:
21
+
22
+
```js
23
+
// import('some-ignored-module')
24
+
/* Some comment about a dynamic import('module') */
25
+
```
26
+
27
+
If you must have a multiline comment then this style is ok (only one `import()` per comment line preceded by an asterisk):
28
+
29
+
```js
30
+
/**
31
+
* Comment about import('module/one')
32
+
* Comment about import('module/two')
33
+
* import('module/three'), etc.
34
+
*/
35
+
```
36
+
37
+
This module uses a [RegExp](https://github.com/morganney/magic-comments-loader/blob/master/src/loader.js#L8) not a parser. If you would like to add better support for ignoring `import()` behind multiline comments please open a pull request. See some more [examples on regexr](https://regexr.com/65fg0).
These are the options that can be configured under the loader `options`. When using comments with a [`config`](#with-config-options) key, you may also specify [`overrides`](#overrides)(`config.match` is ignored inside overrides).
239
+
These are the options that can be configured under the loader `options`. When using comments with a [`config`](#with-config-options) key, you may also specify [`overrides`](#overrides).
214
240
215
241
*`verbose`: Boolean. Prints console statements of the module filepath and updated `import()` during the webpack build. Useful for debugging your custom configurations.
216
242
*`match`: `String(module|import)`. Sets how globs are matched, either the module file path or the `import()` path. Defaults to `'module'`.
@@ -245,7 +271,7 @@ These are the options that can be configured under the loader `options`. When us
245
271
*`String(lazy|lazy-once|eager|weak)`: Adds the comment to **all** dynamic imports using the provided value.
246
272
*`Function`: `(modulePath, importPath) => String(lazy|lazy-once|eager|weak)`. Return falsy value to skip.
247
273
*`config.active`: Boolean | `(modulePath, importPath) => Boolean`. Returning `false` does not add the comment.
248
-
*`config.mode`: `(modulePath, importPath) => String(lazy|lazy-once|eager|weak)`. Return falsy value to skip.
274
+
*`config.mode`: `String(lazy|lazy-once|eager|weak)` | `(modulePath, importPath) => String(lazy|lazy-once|eager|weak)`. Return falsy value to skip.
249
275
*`webpackExports`
250
276
*`Function`: `(modulePath, importPath) => [String(<module names|default>)]`. Return falsy value to skip.
251
277
*`config.active`: Boolean | `(modulePath, importPath) => Boolean`. Returning `false` does not add the comment.
0 commit comments