diff --git a/src/content/api/module-methods.mdx b/src/content/api/module-methods.mdx index 7e8ca75e9fad..8e85d168ba78 100644 --- a/src/content/api/module-methods.mdx +++ b/src/content/api/module-methods.mdx @@ -118,6 +118,7 @@ import( /* webpackChunkName: "my-chunk-name" */ /* webpackMode: "lazy" */ /* webpackExports: ["default", "named"] */ + /* webpackFetchPriority: "high" */ 'module' ); @@ -137,28 +138,55 @@ import( import(/* webpackIgnore: true */ 'ignored-module.js'); ``` -`webpackIgnore`: Disables dynamic import parsing when set to `true`. +##### `webpackIgnore` + +Disables dynamic import parsing when set to `true`. W> Note that setting `webpackIgnore` to `true` opts out of code splitting. -`webpackChunkName`: A name for the new chunk. Since webpack 2.6.0, the placeholders `[index]` and `[request]` are supported within the given string to an incremented number or the actual resolved filename respectively. Adding this comment will cause our separate chunk to be named [my-chunk-name].js instead of [id].js. +##### `webpackChunkName` + +A name for the new chunk. Since webpack 2.6.0, the placeholders `[index]` and `[request]` are supported within the given string to an incremented number or the actual resolved filename respectively. Adding this comment will cause our separate chunk to be named [my-chunk-name].js instead of [id].js. + +##### `webpackFetchPriority` + + -`webpackMode`: Since webpack 2.6.0, different modes for resolving dynamic imports can be specified. The following options are supported: +Set [`fetchPriority`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/fetchPriority) for specific dynamic imports. It's also possible to set a global default value for all dynamic imports by using the [`module.parser.javascript.dynamicImportFetchPriority`](/configuration/module/#moduleparserjavascriptdynamicimportfetchpriority) option. + +```js +import( + /* webpackFetchPriority: "high" */ + 'path/to/module' +); +``` + +##### `webpackMode` + +Since webpack 2.6.0, different modes for resolving dynamic imports can be specified. The following options are supported: - `'lazy'` (default): Generates a lazy-loadable chunk for each `import()`ed module. - `'lazy-once'`: Generates a single lazy-loadable chunk that can satisfy all calls to `import()`. The chunk will be fetched on the first call to `import()`, and subsequent calls to `import()` will use the same network response. Note that this only makes sense in the case of a partially dynamic statement, e.g. `` import(`./locales/${language}.json`) ``, where multiple module paths that can potentially be requested. - `'eager'`: Generates no extra chunk. All modules are included in the current chunk and no additional network requests are made. A `Promise` is still returned but is already resolved. In contrast to a static import, the module isn't executed until the call to `import()` is made. - `'weak'`: Tries to load the module if the module function has already been loaded in some other way (e.g. another chunk imported it or a script containing the module was loaded). A `Promise` is still returned, but only successfully resolves if the chunks are already on the client. If the module is not available, the `Promise` is rejected. A network request will never be performed. This is useful for universal rendering when required chunks are always manually served in initial requests (embedded within the page), but not in cases where app navigation will trigger an import not initially served. -`webpackPrefetch`: Tells the browser that the resource is probably needed for some navigation in the future. Check out the guide for more information on [how webpackPrefetch works](/guides/code-splitting/#prefetchingpreloading-modules). +##### `webpackPrefetch` + +Tells the browser that the resource is probably needed for some navigation in the future. Check out the guide for more information on [how webpackPrefetch works](/guides/code-splitting/#prefetchingpreloading-modules). -`webpackPreload`: Tells the browser that the resource might be needed during the current navigation. Check out the guide for more information on [how webpackPreload works](/guides/code-splitting/#prefetchingpreloading-modules). +##### `webpackPreload` + +Tells the browser that the resource might be needed during the current navigation. Check out the guide for more information on [how webpackPreload works](/guides/code-splitting/#prefetchingpreloading-modules). T> Note that all options can be combined like so `/* webpackMode: "lazy-once", webpackChunkName: "all-i18n-data" */`. This is wrapped in a JavaScript object and executed using [node VM](https://nodejs.org/dist/latest-v8.x/docs/api/vm.html). You do not need to add curly brackets. -`webpackInclude`: A regular expression that will be matched against during import resolution. Only modules that match **will be bundled**. +##### `webpackInclude` + +A regular expression that will be matched against during import resolution. Only modules that match **will be bundled**. + +##### `webpackExclude` -`webpackExclude`: A regular expression that will be matched against during import resolution. Any module that matches **will not be bundled**. +A regular expression that will be matched against during import resolution. Any module that matches **will not be bundled**. T> Note that `webpackInclude` and `webpackExclude` options do not interfere with the prefix. eg: `./locale`. diff --git a/src/content/configuration/module.mdx b/src/content/configuration/module.mdx index c8e5e5ade525..bdfee7ffae38 100644 --- a/src/content/configuration/module.mdx +++ b/src/content/configuration/module.mdx @@ -166,6 +166,26 @@ Note that only `webpackIgnore` comment is supported at the moment: const x = require(/* webpackIgnore: true */ 'x'); ``` +#### module.parser.javascript.dynamicImportFetchPriority + +Specify the global [fetchPriority](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/fetchPriority) for dynamic import. + +- Type: `'low' | 'high' | 'auto' | false` +- Available: 5.87.0+ +- Example: + + ```js + module.exports = { + module: { + parser: { + javascript: { + dynamicImportFetchPriority: 'high', + }, + }, + }, + }; + ``` + #### module.parser.javascript.dynamicImportMode Specifies global mode for dynamic import.