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 |
> i Specifying `chunkFilename` as a `function` is only available in webpack@5
125
+
> Specifying `chunkFilename` as a `function` is only available in webpack@5
108
126
109
127
This option determines the name of non-entry chunk files.
110
128
111
129
Works like [`output.chunkFilename`](https://webpack.js.org/configuration/output/#outputchunkfilename)
112
130
113
131
#### `ignoreOrder`
114
132
115
-
Type: `Boolean`
133
+
Type:
134
+
135
+
```ts
136
+
typeignoreOrder=boolean;
137
+
```
138
+
116
139
Default: `false`
117
140
118
141
Remove Order Warnings.
119
142
See [examples](#remove-order-warnings) below for details.
120
143
121
144
#### `insert`
122
145
123
-
Type: `String|Function`
146
+
Type:
147
+
148
+
```ts
149
+
typeinsert=string| ((linkTag:any) =>void);
150
+
```
151
+
124
152
Default: `document.head.appendChild(linkTag);`
125
153
126
154
> ⚠️ Only for [non-initial (async)](https://webpack.js.org/concepts/under-the-hood/#chunks) chunks.
@@ -133,7 +161,7 @@ In such cases `insert` can be configured to be a function or a custom selector.
133
161
134
162
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
163
136
-
##### `String`
164
+
##### `string`
137
165
138
166
Allows to setup custom [query selector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector).
139
167
A new `<link>` element will be inserted after the found item.
@@ -148,7 +176,7 @@ new MiniCssExtractPlugin({
148
176
149
177
A new `<link>` element will be inserted after the element with id `some-element`.
150
178
151
-
##### `Function`
179
+
##### `function`
152
180
153
181
Allows to override default behavior and insert styles at any position.
154
182
@@ -173,7 +201,12 @@ A new `<link>` element will be inserted before the element with id `some-element
173
201
174
202
#### `attributes`
175
203
176
-
Type: `Object`
204
+
Type:
205
+
206
+
```ts
207
+
typeattributes=object;
208
+
```
209
+
177
210
Default: `{}`
178
211
179
212
> ⚠️ Only for [non-initial (async)](https://webpack.js.org/concepts/under-the-hood/#chunks) chunks.
@@ -209,12 +242,17 @@ Note: It's only applied to dynamically loaded css chunks, if you want to modify
209
242
210
243
#### `linkType`
211
244
212
-
Type: `String|Boolean`
245
+
Type:
246
+
247
+
```ts
248
+
typelinkType=string|boolean;
249
+
```
250
+
213
251
Default: `text/css`
214
252
215
253
This option allows loading asynchronous chunks with a custom link type, such as `<link type="text/css" ...>`.
216
254
217
-
##### `String`
255
+
##### `string`
218
256
219
257
Possible values: `text/css`
220
258
@@ -240,7 +278,7 @@ module.exports = {
240
278
};
241
279
```
242
280
243
-
##### `Boolean`
281
+
##### `boolean`
244
282
245
283
`false` disables the link `type` attribute
246
284
@@ -268,12 +306,17 @@ module.exports = {
268
306
269
307
#### `runtime`
270
308
271
-
Type: `Boolean`
309
+
Type:
310
+
311
+
```ts
312
+
typeruntime=boolean;
313
+
```
314
+
272
315
Default: `true`
273
316
274
317
Allows to enable/disable the runtime generation.
275
318
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.
319
+
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
320
278
321
`true` to skip.
279
322
@@ -301,7 +344,12 @@ module.exports = {
301
344
302
345
#### `experimentalUseImportModule`
303
346
304
-
Type: `Boolean`
347
+
Type:
348
+
349
+
```ts
350
+
typeexperimentalUseImportModule=boolean;
351
+
```
352
+
305
353
Default: `undefined`
306
354
307
355
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 +370,7 @@ module.exports = {
322
370
newMiniCssExtractPlugin({
323
371
// 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
405
353
406
Specifies a custom public path for the external resources like images, files, etc inside `CSS`.
354
407
Works like [`output.publicPath`](https://webpack.js.org/configuration/output/#outputpublicpath)
355
408
356
-
##### `String`
409
+
##### `string`
357
410
358
411
**webpack.config.js**
359
412
@@ -388,7 +441,7 @@ module.exports = {
388
441
};
389
442
```
390
443
391
-
##### `Function`
444
+
##### `function`
392
445
393
446
**webpack.config.js**
394
447
@@ -427,15 +480,25 @@ module.exports = {
427
480
428
481
#### `emit`
429
482
430
-
Type: `Boolean`
483
+
Type:
484
+
485
+
```ts
486
+
typeemit=boolean;
487
+
```
488
+
431
489
Default: `true`
432
490
433
491
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
492
It is often useful to disable this option for server-side packages.
435
493
436
494
#### `esModule`
437
495
438
-
Type: `Boolean`
496
+
Type:
497
+
498
+
```ts
499
+
typeesModule=boolean;
500
+
```
501
+
439
502
Default: `true`
440
503
441
504
By default, `mini-css-extract-plugin` generates JS modules that use the ES modules syntax.
@@ -471,13 +534,13 @@ module.exports = {
471
534
472
535
## Examples
473
536
474
-
### Recommend
537
+
### Recommended
475
538
476
539
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
540
This can be achieved by using the `mini-css-extract-plugin`, because it creates separate css files.
478
541
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
542
480
-
> i Do not use together `style-loader` and `mini-css-extract-plugin`.
543
+
> Do not use `style-loader` and `mini-css-extract-plugin` together.
0 commit comments