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
|**[`filename`](#filename)**|`{String\|Function}`|`[name].css`| This option determines the name of each output CSS file |
85
-
|**[`chunkFilename`](#chunkFilename)**|`{String\|Function}`|`based on filename`| This option determines the name of non-entry chunk files |
86
-
|**[`ignoreOrder`](#ignoreOrder)**|`{Boolean}`|`false`| Remove Order Warnings |
87
-
|**[`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 |
88
-
|**[`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 |
89
-
|**[`linkType`](#linkType)**|`{String\|Boolean}`|`text/css`| Allows loading asynchronous chunks with a custom link type |
90
-
|**[`runtime`](#runtime)**|`{Boolean}`|`true`| Allows to enable/disable the runtime generation |
91
-
|**[`experimentalUseImportModule`](#experimentalUseImportModule)**|`{Boolean}`|`undefined`| Use an experimental webpack API to execute modules instead of child compilers |
Inserts the `link` tag at the given position for [non-initial (async)](https://webpack.js.org/concepts/under-the-hood/#chunks) CSS chunks
161
+
126
162
> ⚠️ Only for [non-initial (async)](https://webpack.js.org/concepts/under-the-hood/#chunks) chunks.
127
163
128
164
By default, the `mini-css-extract-plugin` appends styles (`<link>` elements) to `document.head` of the current `window`.
@@ -133,7 +169,7 @@ In such cases `insert` can be configured to be a function or a custom selector.
133
169
134
170
If you target an [iframe](https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement) make sure that the parent document has sufficient access rights to reach into the frame document and append elements to it.
135
171
136
-
##### `String`
172
+
##### `string`
137
173
138
174
Allows to setup custom [query selector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector).
139
175
A new `<link>` element will be inserted after the found item.
@@ -148,7 +184,7 @@ new MiniCssExtractPlugin({
148
184
149
185
A new `<link>` element will be inserted after the element with id `some-element`.
150
186
151
-
##### `Function`
187
+
##### `function`
152
188
153
189
Allows to override default behavior and insert styles at any position.
154
190
@@ -173,7 +209,12 @@ A new `<link>` element will be inserted before the element with id `some-element
173
209
174
210
#### `attributes`
175
211
176
-
Type: `Object`
212
+
Type:
213
+
214
+
```ts
215
+
typeattributes=Record<string, string>};
216
+
```
217
+
177
218
Default: `{}`
178
219
179
220
> ⚠️ Only for [non-initial (async)](https://webpack.js.org/concepts/under-the-hood/#chunks) chunks.
@@ -209,12 +250,17 @@ Note: It's only applied to dynamically loaded css chunks, if you want to modify
209
250
210
251
#### `linkType`
211
252
212
-
Type: `String|Boolean`
253
+
Type:
254
+
255
+
```ts
256
+
typelinkType=string|boolean;
257
+
```
258
+
213
259
Default: `text/css`
214
260
215
261
This option allows loading asynchronous chunks with a custom link type, such as `<link type="text/css" ...>`.
216
262
217
-
##### `String`
263
+
##### `string`
218
264
219
265
Possible values: `text/css`
220
266
@@ -240,7 +286,7 @@ module.exports = {
240
286
};
241
287
```
242
288
243
-
##### `Boolean`
289
+
##### `boolean`
244
290
245
291
`false` disables the link `type` attribute
246
292
@@ -268,12 +314,17 @@ module.exports = {
268
314
269
315
#### `runtime`
270
316
271
-
Type: `Boolean`
317
+
Type:
318
+
319
+
```ts
320
+
typeruntime=boolean;
321
+
```
322
+
272
323
Default: `true`
273
324
274
325
Allows to enable/disable the runtime generation.
275
326
CSS will be still extracted and can be used for a custom loading methods.
276
-
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.
327
+
For example, you can use [assets-webpack-plugin](https://github.com/ztoben/assets-webpack-plugin) to retrieve them then use your own runtime code to download assets when needed.
277
328
278
329
`true` to skip.
279
330
@@ -301,7 +352,12 @@ module.exports = {
301
352
302
353
#### `experimentalUseImportModule`
303
354
304
-
Type: `Boolean`
355
+
Type:
356
+
357
+
```ts
358
+
typeexperimentalUseImportModule=boolean;
359
+
```
360
+
305
361
Default: `undefined`
306
362
307
363
Enabled by default if not explicitly enabled (i.e. `true` and `false` allow you to explicitly control this option) and new API is available (at least webpack `5.52.0` is required).
@@ -322,7 +378,7 @@ module.exports = {
322
378
newMiniCssExtractPlugin({
323
379
// You don't need this for `>= 5.52.0` due to the fact that this is enabled by default
|**[`publicPath`](#publicPath)**|`{String\|Function}`|`webpackOptions.output.publicPath`| Specifies a custom public path for the external resources like images, files, etc |
345
-
|**[`emit`](#emit)**|`{Boolean}`|`true`| If false, the plugin will extract the CSS but **will not** emit the file |
346
-
|**[`esModule`](#esModule)**|`{Boolean}`|`true`| Use ES modules syntax |
Default: the `publicPath` in `webpackOptions.output`
352
413
353
414
Specifies a custom public path for the external resources like images, files, etc inside `CSS`.
354
415
Works like [`output.publicPath`](https://webpack.js.org/configuration/output/#outputpublicpath)
355
416
356
-
##### `String`
417
+
##### `string`
357
418
358
419
**webpack.config.js**
359
420
@@ -388,7 +449,7 @@ module.exports = {
388
449
};
389
450
```
390
451
391
-
##### `Function`
452
+
##### `function`
392
453
393
454
**webpack.config.js**
394
455
@@ -427,15 +488,25 @@ module.exports = {
427
488
428
489
#### `emit`
429
490
430
-
Type: `Boolean`
491
+
Type:
492
+
493
+
```ts
494
+
typeemit=boolean;
495
+
```
496
+
431
497
Default: `true`
432
498
433
499
If true, emits a file (writes a file to the filesystem). If false, the plugin will extract the CSS but **will not** emit the file.
434
500
It is often useful to disable this option for server-side packages.
435
501
436
502
#### `esModule`
437
503
438
-
Type: `Boolean`
504
+
Type:
505
+
506
+
```ts
507
+
typeesModule=boolean;
508
+
```
509
+
439
510
Default: `true`
440
511
441
512
By default, `mini-css-extract-plugin` generates JS modules that use the ES modules syntax.
@@ -471,13 +542,13 @@ module.exports = {
471
542
472
543
## Examples
473
544
474
-
### Recommend
545
+
### Recommended
475
546
476
547
For `production` builds it's recommended to extract the CSS from your bundle being able to use parallel loading of CSS/JS resources later on.
477
548
This can be achieved by using the `mini-css-extract-plugin`, because it creates separate css files.
478
549
For `development` mode (including `webpack-dev-server`) you can use [style-loader](https://github.com/webpack-contrib/style-loader), because it injects CSS into the DOM using multiple <style></style> and works faster.
479
550
480
-
> i Do not use together `style-loader` and `mini-css-extract-plugin`.
551
+
> Do not use `style-loader` and `mini-css-extract-plugin` together.
0 commit comments