diff --git a/README.md b/README.md index fab71bbd..4f2edb57 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ module.exports = { | **[`insert`](#insert)** | `{String\|Function}` | `document.head.appendChild(linkTag);` | Inserts the `link` tag at the given position for [non-initial (async)](https://webpack.js.org/concepts/under-the-hood/#chunks) CSS chunks | | **[`attributes`](#attributes)** | `{Object}` | `{}` | Adds custom attributes to the `link` tag for [non-initial (async)](https://webpack.js.org/concepts/under-the-hood/#chunks) CSS chunks | | **[`linkType`](#linkType)** | `{String\|Boolean}` | `text/css` | Allows loading asynchronous chunks with a custom link type | -| **[`noRuntime`](#linkType)** | `{Boolean}` | `false` | Skips the runtime generation | +| **[`runtime`](#runtime)** | `{Boolean}` | `true` | Allows to enable/disable the runtime generation | | **[`experimentalUseImportModule`](#experimentalUseImportModule)** | `{Boolean}` | `false` | Use an experimental webpack API to execute modules instead of child compilers | #### `filename` @@ -266,11 +266,14 @@ module.exports = { }; ``` -#### `noRuntime` +#### `runtime` -##### `Boolean` +Type: `Boolean` +Default: `true` -An option to avoid the runtime generation. Assets are still extracted and can be used for a custom loading methods. For example, you can use [assets-webpack-plugin](https://github.com/ztoben/assets-webpack-plugin) to retreive them then use your own runtime code to download assets when needed. +Allows to enable/disable the runtime generation. +CSS will be still extracted and can be used for a custom loading methods. +For example, you can use [assets-webpack-plugin](https://github.com/ztoben/assets-webpack-plugin) to retreive them then use your own runtime code to download assets when needed. `true` to skip. @@ -278,10 +281,11 @@ An option to avoid the runtime generation. Assets are still extracted and can be ```js const MiniCssExtractPlugin = require("mini-css-extract-plugin"); + module.exports = { plugins: [ new MiniCssExtractPlugin({ - skipRuntimeLoading: true, + runtime: false, }), ], module: { diff --git a/src/index.js b/src/index.js index 1378946d..9dd313be 100644 --- a/src/index.js +++ b/src/index.js @@ -337,7 +337,7 @@ class MiniCssExtractPlugin { filename: DEFAULT_FILENAME, ignoreOrder: false, experimentalUseImportModule: false, - noRuntime: false, + runtime: true, }, options ); @@ -521,13 +521,12 @@ class MiniCssExtractPlugin { } }); - // All the code below is dedicated to the runtime and - // can be skipped in a noRuntime context - if (this.options.noRuntime) return; - - const { Template } = webpack; + // All the code below is dedicated to the runtime and can be skipped when the `runtime` option is `false` + if (!this.options.runtime) { + return; + } - const { RuntimeGlobals, runtime } = webpack; + const { Template, RuntimeGlobals, RuntimeModule, runtime } = webpack; // eslint-disable-next-line no-shadow const getCssChunkObject = (mainChunk, compilation) => { @@ -550,8 +549,6 @@ class MiniCssExtractPlugin { return obj; }; - const { RuntimeModule } = webpack; - class CssLoadingRuntimeModule extends RuntimeModule { constructor(runtimeRequirements, runtimeOptions) { super("css loading", 10); diff --git a/src/plugin-options.json b/src/plugin-options.json index 7d70379d..8da511d4 100644 --- a/src/plugin-options.json +++ b/src/plugin-options.json @@ -66,9 +66,9 @@ "description": "This option allows loading asynchronous chunks with a custom link type", "link": "https://github.com/webpack-contrib/mini-css-extract-plugin#linktype" }, - "noRuntime": { + "runtime": { "type": "boolean", - "description": "An option to avoid the runtime generation. Assets are still extracted and can be used for a custom loading methods.", + "description": "Enabled/Disables runtime generation. CSS will be still extracted and can be used for a custom loading methods.", "link": "https://github.com/webpack-contrib/mini-css-extract-plugin#noRuntime" } } diff --git a/test/__snapshots__/noRuntime-option.test.js.snap b/test/__snapshots__/runtime-option.test.js.snap similarity index 57% rename from test/__snapshots__/noRuntime-option.test.js.snap rename to test/__snapshots__/runtime-option.test.js.snap index 93ab1046..56ffd112 100644 --- a/test/__snapshots__/noRuntime-option.test.js.snap +++ b/test/__snapshots__/runtime-option.test.js.snap @@ -1,10 +1,10 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`noRuntime option should work when noRuntime option is "false": DOM 1`] = ` +exports[`noRuntime option should work when the 'runtime' option is 'false': DOM 1`] = ` "