@@ -201,8 +201,8 @@ Allows to override default behavior and insert styles at any position.
201201
202202``` js
203203new MiniCssExtractPlugin ({
204- insert : function (linkTag ) {
205- var reference = document .querySelector (" #some-element" );
204+ insert (linkTag ) {
205+ const reference = document .querySelector (" #some-element" );
206206 if (reference) {
207207 reference .parentNode .insertBefore (linkTag, reference);
208208 }
@@ -217,7 +217,7 @@ A new `<link>` tag will be inserted before the element with the ID `some-element
217217Type:
218218
219219``` ts
220- type attributes = Record <string , string >} ;
220+ type attributes = Record <string , string >;
221221```
222222
223223Default: ` {} `
@@ -483,9 +483,8 @@ module.exports = {
483483 {
484484 loader: MiniCssExtractPlugin .loader ,
485485 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)} /` ,
489488 },
490489 },
491490 " css-loader" ,
@@ -620,6 +619,7 @@ For `development` mode (including `webpack-dev-server`) you can use [style-loade
620619
621620``` js
622621const MiniCssExtractPlugin = require (" mini-css-extract-plugin" );
622+
623623const devMode = process .env .NODE_ENV !== " production" ;
624624
625625module .exports = {
@@ -638,7 +638,7 @@ module.exports = {
638638 },
639639 ],
640640 },
641- plugins: []. concat ( devMode ? [] : [new MiniCssExtractPlugin ()]),
641+ plugins: [devMode ? [] : [new MiniCssExtractPlugin ()]]. flat ( ),
642642};
643643```
644644
@@ -702,7 +702,7 @@ module.exports = {
702702** index.js**
703703
704704``` js
705- import { fooBaz , bar } from " ./styles.css" ;
705+ import { bar , fooBaz } from " ./styles.css" ;
706706
707707console .log (fooBaz, bar);
708708```
@@ -767,12 +767,11 @@ module.exports = {
767767 {
768768 loader: MiniCssExtractPlugin .loader ,
769769 options: {
770- publicPath : (resourcePath , context ) => {
770+ publicPath : (resourcePath , context ) =>
771771 // publicPath is the relative path of the resource to the context
772772 // e.g. for ./css/admin/main.css the publicPath will be ../../
773773 // 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)} /` ,
776775 },
777776 },
778777 " css-loader" ,
@@ -797,8 +796,9 @@ You should not use `HotModuleReplacementPlugin` plugin if you are using a `webpa
797796** webpack.config.js**
798797
799798``` js
800- const webpack = require (" webpack" );
801799const MiniCssExtractPlugin = require (" mini-css-extract-plugin" );
800+ const webpack = require (" webpack" );
801+
802802const devMode = process .env .NODE_ENV !== " production" ;
803803
804804const plugins = [
@@ -848,8 +848,8 @@ You should not use `HotModuleReplacementPlugin` plugin if you are using a `webpa
848848** webpack.config.js**
849849
850850``` js
851- const webpack = require (" webpack" );
852851const MiniCssExtractPlugin = require (" mini-css-extract-plugin" );
852+ const webpack = require (" webpack" );
853853
854854const plugins = [
855855 new MiniCssExtractPlugin ({
@@ -890,8 +890,8 @@ To minify the output, use a plugin like [css-minimizer-webpack-plugin](https://g
890890** webpack.config.js**
891891
892892``` js
893- const MiniCssExtractPlugin = require (" mini-css-extract-plugin" );
894893const CssMinimizerPlugin = require (" css-minimizer-webpack-plugin" );
894+ const MiniCssExtractPlugin = require (" mini-css-extract-plugin" );
895895
896896module .exports = {
897897 plugins: [
@@ -992,17 +992,13 @@ module.exports = {
992992 fooStyles: {
993993 type: " css/mini-extract" ,
994994 name: " styles_foo" ,
995- chunks : (chunk ) => {
996- return chunk .name === " foo" ;
997- },
995+ chunks : (chunk ) => chunk .name === " foo" ,
998996 enforce: true ,
999997 },
1000998 barStyles: {
1001999 type: " css/mini-extract" ,
10021000 name: " styles_bar" ,
1003- chunks : (chunk ) => {
1004- return chunk .name === " bar" ;
1005- },
1001+ chunks : (chunk ) => chunk .name === " bar" ,
10061002 enforce: true ,
10071003 },
10081004 },
@@ -1129,7 +1125,7 @@ module.exports = {
11291125 {
11301126 loader: " sass-loader" ,
11311127 options: {
1132- additionalData: ` @use 'dark-theme/vars' as vars;` ,
1128+ additionalData: " @use 'dark-theme/vars' as vars;" ,
11331129 },
11341130 },
11351131 ],
@@ -1141,7 +1137,7 @@ module.exports = {
11411137 {
11421138 loader: " sass-loader" ,
11431139 options: {
1144- additionalData: ` @use 'light-theme/vars' as vars;` ,
1140+ additionalData: " @use 'light-theme/vars' as vars;" ,
11451141 },
11461142 },
11471143 ],
@@ -1163,7 +1159,7 @@ module.exports = {
11631159
11641160** src/index.js**
11651161
1166- ``` js
1162+ ```
11671163import "./style.scss";
11681164
11691165let theme = "light";
@@ -1172,7 +1168,6 @@ const themes = {};
11721168themes[theme] = document.querySelector("#theme");
11731169
11741170async function loadTheme(newTheme) {
1175- // eslint-disable-next-line no-console
11761171 console.log(`CHANGE THEME - ${newTheme}`);
11771172
11781173 const themeElement = document.querySelector("#theme");
@@ -1182,7 +1177,6 @@ async function loadTheme(newTheme) {
11821177 }
11831178
11841179 if (themes[newTheme]) {
1185- // eslint-disable-next-line no-console
11861180 console.log(`THEME ALREADY LOADED - ${newTheme}`);
11871181
11881182 document.head.appendChild(themes[newTheme]);
@@ -1191,13 +1185,11 @@ async function loadTheme(newTheme) {
11911185 }
11921186
11931187 if (newTheme === "dark") {
1194- // eslint-disable-next-line no-console
11951188 console.log(`LOADING THEME - ${newTheme}`);
11961189
11971190 import(/* webpackChunkName: "dark" */ "./style.scss?dark").then(() => {
11981191 themes[newTheme] = document.querySelector("#theme");
11991192
1200- // eslint-disable-next-line no-console
12011193 console.log(`LOADED - ${newTheme}`);
12021194 });
12031195 }
@@ -1275,7 +1267,7 @@ MiniCssExtractPlugin.getCompilationHooks(compilation).beforeTagInsert.tap(
12751267 Template .asString ([
12761268 source,
12771269 ` ${ varNames .tag } .setAttribute("href", "https://github.com/webpack-contrib/mini-css-extract-plugin");` ,
1278- ])
1270+ ]),
12791271);
12801272```
12811273
0 commit comments