@@ -201,8 +201,8 @@ Allows to override default behavior and insert styles at any position.
201
201
202
202
``` js
203
203
new MiniCssExtractPlugin ({
204
- insert : function (linkTag ) {
205
- var reference = document .querySelector (" #some-element" );
204
+ insert (linkTag ) {
205
+ const reference = document .querySelector (" #some-element" );
206
206
if (reference) {
207
207
reference .parentNode .insertBefore (linkTag, reference);
208
208
}
@@ -217,7 +217,7 @@ A new `<link>` tag will be inserted before the element with the ID `some-element
217
217
Type:
218
218
219
219
``` ts
220
- type attributes = Record <string , string >} ;
220
+ type attributes = Record <string , string >;
221
221
```
222
222
223
223
Default: ` {} `
@@ -483,9 +483,8 @@ module.exports = {
483
483
{
484
484
loader: MiniCssExtractPlugin .loader ,
485
485
options: {
486
- publicPath : (resourcePath , context ) => {
487
- return path .relative (path .dirname (resourcePath), context) + " /" ;
488
- },
486
+ publicPath : (resourcePath , context ) =>
487
+ ` ${ path .relative (path .dirname (resourcePath), context)} /` ,
489
488
},
490
489
},
491
490
" css-loader" ,
@@ -620,6 +619,7 @@ For `development` mode (including `webpack-dev-server`) you can use [style-loade
620
619
621
620
``` js
622
621
const MiniCssExtractPlugin = require (" mini-css-extract-plugin" );
622
+
623
623
const devMode = process .env .NODE_ENV !== " production" ;
624
624
625
625
module .exports = {
@@ -638,7 +638,7 @@ module.exports = {
638
638
},
639
639
],
640
640
},
641
- plugins: []. concat ( devMode ? [] : [new MiniCssExtractPlugin ()]),
641
+ plugins: [devMode ? [] : [new MiniCssExtractPlugin ()]]. flat ( ),
642
642
};
643
643
```
644
644
@@ -702,7 +702,7 @@ module.exports = {
702
702
** index.js**
703
703
704
704
``` js
705
- import { fooBaz , bar } from " ./styles.css" ;
705
+ import { bar , fooBaz } from " ./styles.css" ;
706
706
707
707
console .log (fooBaz, bar);
708
708
```
@@ -767,12 +767,11 @@ module.exports = {
767
767
{
768
768
loader: MiniCssExtractPlugin .loader ,
769
769
options: {
770
- publicPath : (resourcePath , context ) => {
770
+ publicPath : (resourcePath , context ) =>
771
771
// publicPath is the relative path of the resource to the context
772
772
// e.g. for ./css/admin/main.css the publicPath will be ../../
773
773
// while for ./css/main.css the publicPath will be ../
774
- return path .relative (path .dirname (resourcePath), context) + " /" ;
775
- },
774
+ ` ${ path .relative (path .dirname (resourcePath), context)} /` ,
776
775
},
777
776
},
778
777
" css-loader" ,
@@ -797,8 +796,9 @@ You should not use `HotModuleReplacementPlugin` plugin if you are using a `webpa
797
796
** webpack.config.js**
798
797
799
798
``` js
800
- const webpack = require (" webpack" );
801
799
const MiniCssExtractPlugin = require (" mini-css-extract-plugin" );
800
+ const webpack = require (" webpack" );
801
+
802
802
const devMode = process .env .NODE_ENV !== " production" ;
803
803
804
804
const plugins = [
@@ -848,8 +848,8 @@ You should not use `HotModuleReplacementPlugin` plugin if you are using a `webpa
848
848
** webpack.config.js**
849
849
850
850
``` js
851
- const webpack = require (" webpack" );
852
851
const MiniCssExtractPlugin = require (" mini-css-extract-plugin" );
852
+ const webpack = require (" webpack" );
853
853
854
854
const plugins = [
855
855
new MiniCssExtractPlugin ({
@@ -890,8 +890,8 @@ To minify the output, use a plugin like [css-minimizer-webpack-plugin](https://g
890
890
** webpack.config.js**
891
891
892
892
``` js
893
- const MiniCssExtractPlugin = require (" mini-css-extract-plugin" );
894
893
const CssMinimizerPlugin = require (" css-minimizer-webpack-plugin" );
894
+ const MiniCssExtractPlugin = require (" mini-css-extract-plugin" );
895
895
896
896
module .exports = {
897
897
plugins: [
@@ -992,17 +992,13 @@ module.exports = {
992
992
fooStyles: {
993
993
type: " css/mini-extract" ,
994
994
name: " styles_foo" ,
995
- chunks : (chunk ) => {
996
- return chunk .name === " foo" ;
997
- },
995
+ chunks : (chunk ) => chunk .name === " foo" ,
998
996
enforce: true ,
999
997
},
1000
998
barStyles: {
1001
999
type: " css/mini-extract" ,
1002
1000
name: " styles_bar" ,
1003
- chunks : (chunk ) => {
1004
- return chunk .name === " bar" ;
1005
- },
1001
+ chunks : (chunk ) => chunk .name === " bar" ,
1006
1002
enforce: true ,
1007
1003
},
1008
1004
},
@@ -1129,7 +1125,7 @@ module.exports = {
1129
1125
{
1130
1126
loader: " sass-loader" ,
1131
1127
options: {
1132
- additionalData: ` @use 'dark-theme/vars' as vars;` ,
1128
+ additionalData: " @use 'dark-theme/vars' as vars;" ,
1133
1129
},
1134
1130
},
1135
1131
],
@@ -1141,7 +1137,7 @@ module.exports = {
1141
1137
{
1142
1138
loader: " sass-loader" ,
1143
1139
options: {
1144
- additionalData: ` @use 'light-theme/vars' as vars;` ,
1140
+ additionalData: " @use 'light-theme/vars' as vars;" ,
1145
1141
},
1146
1142
},
1147
1143
],
@@ -1163,7 +1159,7 @@ module.exports = {
1163
1159
1164
1160
** src/index.js**
1165
1161
1166
- ``` js
1162
+ ```
1167
1163
import "./style.scss";
1168
1164
1169
1165
let theme = "light";
@@ -1172,7 +1168,6 @@ const themes = {};
1172
1168
themes[theme] = document.querySelector("#theme");
1173
1169
1174
1170
async function loadTheme(newTheme) {
1175
- // eslint-disable-next-line no-console
1176
1171
console.log(`CHANGE THEME - ${newTheme}`);
1177
1172
1178
1173
const themeElement = document.querySelector("#theme");
@@ -1182,7 +1177,6 @@ async function loadTheme(newTheme) {
1182
1177
}
1183
1178
1184
1179
if (themes[newTheme]) {
1185
- // eslint-disable-next-line no-console
1186
1180
console.log(`THEME ALREADY LOADED - ${newTheme}`);
1187
1181
1188
1182
document.head.appendChild(themes[newTheme]);
@@ -1191,13 +1185,11 @@ async function loadTheme(newTheme) {
1191
1185
}
1192
1186
1193
1187
if (newTheme === "dark") {
1194
- // eslint-disable-next-line no-console
1195
1188
console.log(`LOADING THEME - ${newTheme}`);
1196
1189
1197
1190
import(/* webpackChunkName: "dark" */ "./style.scss?dark").then(() => {
1198
1191
themes[newTheme] = document.querySelector("#theme");
1199
1192
1200
- // eslint-disable-next-line no-console
1201
1193
console.log(`LOADED - ${newTheme}`);
1202
1194
});
1203
1195
}
@@ -1275,7 +1267,7 @@ MiniCssExtractPlugin.getCompilationHooks(compilation).beforeTagInsert.tap(
1275
1267
Template .asString ([
1276
1268
source,
1277
1269
` ${ varNames .tag } .setAttribute("href", "https://github.com/webpack-contrib/mini-css-extract-plugin");` ,
1278
- ])
1270
+ ]),
1279
1271
);
1280
1272
```
1281
1273
0 commit comments