  \href{https://webpack.js.org/}{\texttt{  }} \doxysection*{mini-\/css-\/extract-\/plugin}

 

\href{https://npmjs.com/package/mini-css-extract-plugin}{\texttt{ }} \href{https://nodejs.org}{\texttt{ }} \href{https://david-dm.org/webpack-contrib/mini-css-extract-plugin}{\texttt{ }} \href{https://github.com/webpack-contrib/mini-css-extract-plugin/actions}{\texttt{ }} \href{https://codecov.io/gh/webpack-contrib/mini-css-extract-plugin}{\texttt{ }} \href{https://gitter.im/webpack/webpack}{\texttt{ }} \href{https://packagephobia.now.sh/result?p=mini-css-extract-plugin}{\texttt{ }}\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17568}{}\doxysection{mini-\/css-\/extract-\/plugin}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17568}
This plugin extracts CSS into separate files. It creates a CSS file per JS file which contains CSS. It supports On-\/\+Demand-\/\+Loading of CSS and Source\+Maps.

It builds on top of a new webpack v4 feature (module types) and requires webpack 4 to work.

Compared to the extract-\/text-\/webpack-\/plugin\+:


\begin{DoxyItemize}
\item Async loading
\item No duplicate compilation (performance)
\item Easier to use
\item Specific to CSS
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17569}{}\doxysubsection{Getting Started}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17569}
To begin, you\textquotesingle{}ll need to install {\ttfamily mini-\/css-\/extract-\/plugin}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{npm install -\/-\/save-\/dev mini-\/css-\/extract-\/plugin }

\end{DoxyCode}


It\textquotesingle{}s recommended to combine {\ttfamily mini-\/css-\/extract-\/plugin} with the \href{https://github.com/webpack-contrib/css-loader}{\texttt{ {\ttfamily css-\/loader}}}

Then add the loader and the plugin to your {\ttfamily webpack} config. For example\+:

{\bfseries{style.\+css}}


\begin{DoxyCode}{0}
\DoxyCodeLine{body \{}
\DoxyCodeLine{  background: green;}
\DoxyCodeLine{\} }

\end{DoxyCode}


{\bfseries{component.\+js}}


\begin{DoxyCode}{0}
\DoxyCodeLine{import './style.css'; }

\end{DoxyCode}


{\bfseries{webpack.\+config.\+js}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const MiniCssExtractPlugin = require('mini-\/css-\/extract-\/plugin');}
\DoxyCodeLine{}
\DoxyCodeLine{module.exports = \{}
\DoxyCodeLine{  plugins: [new MiniCssExtractPlugin()],}
\DoxyCodeLine{  module: \{}
\DoxyCodeLine{    rules: [}
\DoxyCodeLine{      \{}
\DoxyCodeLine{        test: /\(\backslash\).css\$/i,}
\DoxyCodeLine{        use: [MiniCssExtractPlugin.loader, 'css-\/loader'],}
\DoxyCodeLine{      \},}
\DoxyCodeLine{    ],}
\DoxyCodeLine{  \},}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17570}{}\doxysubsection{Options}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17570}
\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17571}{}\doxysubsubsection{$<$tt$>$public\+Path$<$/tt$>$}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17571}
Type\+: {\ttfamily String$\vert$\+Function} Default\+: the {\ttfamily public\+Path} in {\ttfamily webpack\+Options.\+output}

Specifies a custom public path for the target file(s).\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17572}{}\doxyparagraph{$<$tt$>$\+String$<$/tt$>$}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17572}
{\bfseries{webpack.\+config.\+js}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const MiniCssExtractPlugin = require('mini-\/css-\/extract-\/plugin');}
\DoxyCodeLine{}
\DoxyCodeLine{module.exports = \{}
\DoxyCodeLine{  plugins: [}
\DoxyCodeLine{    new MiniCssExtractPlugin(\{}
\DoxyCodeLine{      // Options similar to the same options in webpackOptions.output}
\DoxyCodeLine{      // both options are optional}
\DoxyCodeLine{      filename: '[name].css',}
\DoxyCodeLine{      chunkFilename: '[id].css',}
\DoxyCodeLine{    \}),}
\DoxyCodeLine{  ],}
\DoxyCodeLine{  module: \{}
\DoxyCodeLine{    rules: [}
\DoxyCodeLine{      \{}
\DoxyCodeLine{        test: /\(\backslash\).css\$/,}
\DoxyCodeLine{        use: [}
\DoxyCodeLine{          \{}
\DoxyCodeLine{            loader: MiniCssExtractPlugin.loader,}
\DoxyCodeLine{            options: \{}
\DoxyCodeLine{              publicPath: '/public/path/to/',}
\DoxyCodeLine{            \},}
\DoxyCodeLine{          \},}
\DoxyCodeLine{          'css-\/loader',}
\DoxyCodeLine{        ],}
\DoxyCodeLine{      \},}
\DoxyCodeLine{    ],}
\DoxyCodeLine{  \},}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17573}{}\doxyparagraph{$<$tt$>$\+Function$<$/tt$>$}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17573}
{\bfseries{webpack.\+config.\+js}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const MiniCssExtractPlugin = require('mini-\/css-\/extract-\/plugin');}
\DoxyCodeLine{}
\DoxyCodeLine{module.exports = \{}
\DoxyCodeLine{  plugins: [}
\DoxyCodeLine{    new MiniCssExtractPlugin(\{}
\DoxyCodeLine{      // Options similar to the same options in webpackOptions.output}
\DoxyCodeLine{      // both options are optional}
\DoxyCodeLine{      filename: '[name].css',}
\DoxyCodeLine{      chunkFilename: '[id].css',}
\DoxyCodeLine{    \}),}
\DoxyCodeLine{  ],}
\DoxyCodeLine{  module: \{}
\DoxyCodeLine{    rules: [}
\DoxyCodeLine{      \{}
\DoxyCodeLine{        test: /\(\backslash\).css\$/,}
\DoxyCodeLine{        use: [}
\DoxyCodeLine{          \{}
\DoxyCodeLine{            loader: MiniCssExtractPlugin.loader,}
\DoxyCodeLine{            options: \{}
\DoxyCodeLine{              publicPath: (resourcePath, context) => \{}
\DoxyCodeLine{                return path.relative(path.dirname(resourcePath), context) + '/';}
\DoxyCodeLine{              \},}
\DoxyCodeLine{            \},}
\DoxyCodeLine{          \},}
\DoxyCodeLine{          'css-\/loader',}
\DoxyCodeLine{        ],}
\DoxyCodeLine{      \},}
\DoxyCodeLine{    ],}
\DoxyCodeLine{  \},}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17574}{}\doxysubsubsection{$<$tt$>$es\+Module$<$/tt$>$}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17574}
Type\+: {\ttfamily Boolean} Default\+: {\ttfamily false}

By default, {\ttfamily mini-\/css-\/extract-\/plugin} generates JS modules that use the Common\+JS modules syntax. There are some cases in which using ES modules is beneficial, like in the case of \href{https://webpack.js.org/plugins/module-concatenation-plugin/}{\texttt{ module concatenation}} and \href{https://webpack.js.org/guides/tree-shaking/}{\texttt{ tree shaking}}.

You can enable a ES module syntax using\+:

{\bfseries{webpack.\+config.\+js}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const MiniCssExtractPlugin = require('mini-\/css-\/extract-\/plugin');}
\DoxyCodeLine{}
\DoxyCodeLine{module.exports = \{}
\DoxyCodeLine{  plugins: [new MiniCssExtractPlugin()],}
\DoxyCodeLine{  module: \{}
\DoxyCodeLine{    rules: [}
\DoxyCodeLine{      \{}
\DoxyCodeLine{        test: /\(\backslash\).css\$/i,}
\DoxyCodeLine{        use: [}
\DoxyCodeLine{          \{}
\DoxyCodeLine{            loader: MiniCssExtractPlugin.loader,}
\DoxyCodeLine{            options: \{}
\DoxyCodeLine{              esModule: true,}
\DoxyCodeLine{            \},}
\DoxyCodeLine{          \},}
\DoxyCodeLine{          'css-\/loader',}
\DoxyCodeLine{        ],}
\DoxyCodeLine{      \},}
\DoxyCodeLine{    ],}
\DoxyCodeLine{  \},}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17575}{}\doxysubsection{Examples}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17575}
\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17576}{}\doxysubsubsection{Minimal example}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17576}
{\bfseries{webpack.\+config.\+js}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const MiniCssExtractPlugin = require('mini-\/css-\/extract-\/plugin');}
\DoxyCodeLine{}
\DoxyCodeLine{module.exports = \{}
\DoxyCodeLine{  plugins: [}
\DoxyCodeLine{    new MiniCssExtractPlugin(\{}
\DoxyCodeLine{      // Options similar to the same options in webpackOptions.output}
\DoxyCodeLine{      // all options are optional}
\DoxyCodeLine{      filename: '[name].css',}
\DoxyCodeLine{      chunkFilename: '[id].css',}
\DoxyCodeLine{      ignoreOrder: false, // Enable to remove warnings about conflicting order}
\DoxyCodeLine{    \}),}
\DoxyCodeLine{  ],}
\DoxyCodeLine{  module: \{}
\DoxyCodeLine{    rules: [}
\DoxyCodeLine{      \{}
\DoxyCodeLine{        test: /\(\backslash\).css\$/,}
\DoxyCodeLine{        use: [}
\DoxyCodeLine{          \{}
\DoxyCodeLine{            loader: MiniCssExtractPlugin.loader,}
\DoxyCodeLine{            options: \{}
\DoxyCodeLine{              // you can specify a publicPath here}
\DoxyCodeLine{              // by default it uses publicPath in webpackOptions.output}
\DoxyCodeLine{              publicPath: '../',}
\DoxyCodeLine{              hmr: process.env.NODE\_ENV === 'development',}
\DoxyCodeLine{            \},}
\DoxyCodeLine{          \},}
\DoxyCodeLine{          'css-\/loader',}
\DoxyCodeLine{        ],}
\DoxyCodeLine{      \},}
\DoxyCodeLine{    ],}
\DoxyCodeLine{  \},}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17577}{}\doxysubsubsection{The $<$tt$>$public\+Path$<$/tt$>$ option as function}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17577}
{\bfseries{webpack.\+config.\+js}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const MiniCssExtractPlugin = require('mini-\/css-\/extract-\/plugin');}
\DoxyCodeLine{}
\DoxyCodeLine{module.exports = \{}
\DoxyCodeLine{  plugins: [}
\DoxyCodeLine{    new MiniCssExtractPlugin(\{}
\DoxyCodeLine{      // Options similar to the same options in webpackOptions.output}
\DoxyCodeLine{      // both options are optional}
\DoxyCodeLine{      filename: '[name].css',}
\DoxyCodeLine{      chunkFilename: '[id].css',}
\DoxyCodeLine{    \}),}
\DoxyCodeLine{  ],}
\DoxyCodeLine{  module: \{}
\DoxyCodeLine{    rules: [}
\DoxyCodeLine{      \{}
\DoxyCodeLine{        test: /\(\backslash\).css\$/,}
\DoxyCodeLine{        use: [}
\DoxyCodeLine{          \{}
\DoxyCodeLine{            loader: MiniCssExtractPlugin.loader,}
\DoxyCodeLine{            options: \{}
\DoxyCodeLine{              publicPath: (resourcePath, context) => \{}
\DoxyCodeLine{                // publicPath is the relative path of the resource to the context}
\DoxyCodeLine{                // e.g. for ./css/admin/main.css the publicPath will be ../../}
\DoxyCodeLine{                // while for ./css/main.css the publicPath will be ../}
\DoxyCodeLine{                return path.relative(path.dirname(resourcePath), context) + '/';}
\DoxyCodeLine{              \},}
\DoxyCodeLine{            \},}
\DoxyCodeLine{          \},}
\DoxyCodeLine{          'css-\/loader',}
\DoxyCodeLine{        ],}
\DoxyCodeLine{      \},}
\DoxyCodeLine{    ],}
\DoxyCodeLine{  \},}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17578}{}\doxysubsubsection{Advanced configuration example}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17578}
This plugin should be used only on {\ttfamily production} builds without {\ttfamily style-\/loader} in the loaders chain, especially if you want to have HMR in {\ttfamily development}.

Here is an example to have both HMR in {\ttfamily development} and your styles extracted in a file for {\ttfamily production} builds.

(Loaders options left out for clarity, adapt accordingly to your needs.)

{\bfseries{webpack.\+config.\+js}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const MiniCssExtractPlugin = require('mini-\/css-\/extract-\/plugin');}
\DoxyCodeLine{const devMode = process.env.NODE\_ENV !== 'production';}
\DoxyCodeLine{}
\DoxyCodeLine{module.exports = \{}
\DoxyCodeLine{  plugins: [}
\DoxyCodeLine{    new MiniCssExtractPlugin(\{}
\DoxyCodeLine{      // Options similar to the same options in webpackOptions.output}
\DoxyCodeLine{      // both options are optional}
\DoxyCodeLine{      filename: devMode ? '[name].css' : '[name].[hash].css',}
\DoxyCodeLine{      chunkFilename: devMode ? '[id].css' : '[id].[hash].css',}
\DoxyCodeLine{    \}),}
\DoxyCodeLine{  ],}
\DoxyCodeLine{  module: \{}
\DoxyCodeLine{    rules: [}
\DoxyCodeLine{      \{}
\DoxyCodeLine{        test: /\(\backslash\).(sa|sc|c)ss\$/,}
\DoxyCodeLine{        use: [}
\DoxyCodeLine{          \{}
\DoxyCodeLine{            loader: MiniCssExtractPlugin.loader,}
\DoxyCodeLine{            options: \{}
\DoxyCodeLine{              hmr: process.env.NODE\_ENV === 'development',}
\DoxyCodeLine{            \},}
\DoxyCodeLine{          \},}
\DoxyCodeLine{          'css-\/loader',}
\DoxyCodeLine{          'postcss-\/loader',}
\DoxyCodeLine{          'sass-\/loader',}
\DoxyCodeLine{        ],}
\DoxyCodeLine{      \},}
\DoxyCodeLine{    ],}
\DoxyCodeLine{  \},}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17579}{}\doxysubsubsection{Hot Module Reloading (\+HMR)}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17579}
The {\ttfamily mini-\/css-\/extract-\/plugin} supports hot reloading of actual css files in development. Some options are provided to enable HMR of both standard stylesheets and locally scoped CSS or CSS modules. Below is an example configuration of mini-\/css for HMR use with CSS modules.

While we attempt to hmr css-\/modules. It is not easy to perform when code-\/splitting with custom chunk names. {\ttfamily reload\+All} is an option that should only be enabled if HMR isn\textquotesingle{}t working correctly. The core challenge with css-\/modules is that when code-\/split, the chunk ids can and do end up different compared to the filename.

{\bfseries{webpack.\+config.\+js}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const MiniCssExtractPlugin = require('mini-\/css-\/extract-\/plugin');}
\DoxyCodeLine{}
\DoxyCodeLine{module.exports = \{}
\DoxyCodeLine{  plugins: [}
\DoxyCodeLine{    new MiniCssExtractPlugin(\{}
\DoxyCodeLine{      // Options similar to the same options in webpackOptions.output}
\DoxyCodeLine{      // both options are optional}
\DoxyCodeLine{      filename: '[name].css',}
\DoxyCodeLine{      chunkFilename: '[id].css',}
\DoxyCodeLine{    \}),}
\DoxyCodeLine{  ],}
\DoxyCodeLine{  module: \{}
\DoxyCodeLine{    rules: [}
\DoxyCodeLine{      \{}
\DoxyCodeLine{        test: /\(\backslash\).css\$/,}
\DoxyCodeLine{        use: [}
\DoxyCodeLine{          \{}
\DoxyCodeLine{            loader: MiniCssExtractPlugin.loader,}
\DoxyCodeLine{            options: \{}
\DoxyCodeLine{              // only enable hot in development}
\DoxyCodeLine{              hmr: process.env.NODE\_ENV === 'development',}
\DoxyCodeLine{              // if hmr does not work, this is a forceful method.}
\DoxyCodeLine{              reloadAll: true,}
\DoxyCodeLine{            \},}
\DoxyCodeLine{          \},}
\DoxyCodeLine{          'css-\/loader',}
\DoxyCodeLine{        ],}
\DoxyCodeLine{      \},}
\DoxyCodeLine{    ],}
\DoxyCodeLine{  \},}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17580}{}\doxysubsubsection{Minimizing For Production}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17580}
To minify the output, use a plugin like \href{https://github.com/NMFR/optimize-css-assets-webpack-plugin}{\texttt{ optimize-\/css-\/assets-\/webpack-\/plugin}}. Setting {\ttfamily optimization.\+minimizer} overrides the defaults provided by webpack, so make sure to also specify a JS minimizer\+:

{\bfseries{webpack.\+config.\+js}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const TerserJSPlugin = require('terser-\/webpack-\/plugin');}
\DoxyCodeLine{const MiniCssExtractPlugin = require('mini-\/css-\/extract-\/plugin');}
\DoxyCodeLine{const OptimizeCSSAssetsPlugin = require('optimize-\/css-\/assets-\/webpack-\/plugin');}
\DoxyCodeLine{}
\DoxyCodeLine{module.exports = \{}
\DoxyCodeLine{  optimization: \{}
\DoxyCodeLine{    minimizer: [new TerserJSPlugin(\{\}), new OptimizeCSSAssetsPlugin(\{\})],}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  plugins: [}
\DoxyCodeLine{    new MiniCssExtractPlugin(\{}
\DoxyCodeLine{      filename: '[name].css',}
\DoxyCodeLine{      chunkFilename: '[id].css',}
\DoxyCodeLine{    \}),}
\DoxyCodeLine{  ],}
\DoxyCodeLine{  module: \{}
\DoxyCodeLine{    rules: [}
\DoxyCodeLine{      \{}
\DoxyCodeLine{        test: /\(\backslash\).css\$/,}
\DoxyCodeLine{        use: [MiniCssExtractPlugin.loader, 'css-\/loader'],}
\DoxyCodeLine{      \},}
\DoxyCodeLine{    ],}
\DoxyCodeLine{  \},}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17581}{}\doxysubsubsection{Using preloaded or inlined CSS}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17581}
The runtime code detects already added CSS via {\ttfamily $<$link$>$} or {\ttfamily $<$style$>$} tag. This can be useful when injecting CSS on server-\/side for Server-\/\+Side-\/\+Rendering. The {\ttfamily href} of the {\ttfamily $<$link$>$} tag has to match the URL that will be used for loading the CSS chunk. The {\ttfamily data-\/href} attribute can be used for {\ttfamily $<$link$>$} and {\ttfamily $<$style$>$} too. When inlining CSS {\ttfamily data-\/href} must be used.\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17582}{}\doxysubsubsection{Extracting all CSS in a single file}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17582}
The CSS can be extracted in one CSS file using {\ttfamily optimization.\+split\+Chunks.\+cache\+Groups}.

{\bfseries{webpack.\+config.\+js}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const MiniCssExtractPlugin = require('mini-\/css-\/extract-\/plugin');}
\DoxyCodeLine{}
\DoxyCodeLine{module.exports = \{}
\DoxyCodeLine{  optimization: \{}
\DoxyCodeLine{    splitChunks: \{}
\DoxyCodeLine{      cacheGroups: \{}
\DoxyCodeLine{        styles: \{}
\DoxyCodeLine{          name: 'styles',}
\DoxyCodeLine{          test: /\(\backslash\).css\$/,}
\DoxyCodeLine{          chunks: 'all',}
\DoxyCodeLine{          enforce: true,}
\DoxyCodeLine{        \},}
\DoxyCodeLine{      \},}
\DoxyCodeLine{    \},}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  plugins: [}
\DoxyCodeLine{    new MiniCssExtractPlugin(\{}
\DoxyCodeLine{      filename: '[name].css',}
\DoxyCodeLine{    \}),}
\DoxyCodeLine{  ],}
\DoxyCodeLine{  module: \{}
\DoxyCodeLine{    rules: [}
\DoxyCodeLine{      \{}
\DoxyCodeLine{        test: /\(\backslash\).css\$/,}
\DoxyCodeLine{        use: [MiniCssExtractPlugin.loader, 'css-\/loader'],}
\DoxyCodeLine{      \},}
\DoxyCodeLine{    ],}
\DoxyCodeLine{  \},}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17583}{}\doxysubsubsection{Extracting CSS based on entry}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17583}
You may also extract the CSS based on the webpack entry name. This is especially useful if you import routes dynamically but want to keep your CSS bundled according to entry. This also prevents the CSS duplication issue one had with the Extract\+Text\+Plugin.


\begin{DoxyCode}{0}
\DoxyCodeLine{const path = require('path');}
\DoxyCodeLine{const MiniCssExtractPlugin = require('mini-\/css-\/extract-\/plugin');}
\DoxyCodeLine{}
\DoxyCodeLine{function recursiveIssuer(m) \{}
\DoxyCodeLine{  if (m.issuer) \{}
\DoxyCodeLine{    return recursiveIssuer(m.issuer);}
\DoxyCodeLine{  \} else if (m.name) \{}
\DoxyCodeLine{    return m.name;}
\DoxyCodeLine{  \} else \{}
\DoxyCodeLine{    return false;}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{module.exports = \{}
\DoxyCodeLine{  entry: \{}
\DoxyCodeLine{    foo: path.resolve(\_\_dirname, 'src/foo'),}
\DoxyCodeLine{    bar: path.resolve(\_\_dirname, 'src/bar'),}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  optimization: \{}
\DoxyCodeLine{    splitChunks: \{}
\DoxyCodeLine{      cacheGroups: \{}
\DoxyCodeLine{        fooStyles: \{}
\DoxyCodeLine{          name: 'foo',}
\DoxyCodeLine{          test: (m, c, entry = 'foo') =>}
\DoxyCodeLine{            m.constructor.name === 'CssModule' \&\& recursiveIssuer(m) === entry,}
\DoxyCodeLine{          chunks: 'all',}
\DoxyCodeLine{          enforce: true,}
\DoxyCodeLine{        \},}
\DoxyCodeLine{        barStyles: \{}
\DoxyCodeLine{          name: 'bar',}
\DoxyCodeLine{          test: (m, c, entry = 'bar') =>}
\DoxyCodeLine{            m.constructor.name === 'CssModule' \&\& recursiveIssuer(m) === entry,}
\DoxyCodeLine{          chunks: 'all',}
\DoxyCodeLine{          enforce: true,}
\DoxyCodeLine{        \},}
\DoxyCodeLine{      \},}
\DoxyCodeLine{    \},}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  plugins: [}
\DoxyCodeLine{    new MiniCssExtractPlugin(\{}
\DoxyCodeLine{      filename: '[name].css',}
\DoxyCodeLine{    \}),}
\DoxyCodeLine{  ],}
\DoxyCodeLine{  module: \{}
\DoxyCodeLine{    rules: [}
\DoxyCodeLine{      \{}
\DoxyCodeLine{        test: /\(\backslash\).css\$/,}
\DoxyCodeLine{        use: [MiniCssExtractPlugin.loader, 'css-\/loader'],}
\DoxyCodeLine{      \},}
\DoxyCodeLine{    ],}
\DoxyCodeLine{  \},}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17584}{}\doxysubsubsection{Module Filename Option}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17584}
With the {\ttfamily module\+Filename} option you can use chunk data to customize the filename. This is particularly useful when dealing with multiple entry points and wanting to get more control out of the filename for a given entry point/chunk. In the example below, we\textquotesingle{}ll use {\ttfamily module\+Filename} to output the generated css into a different directory.

{\bfseries{webpack.\+config.\+js}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const MiniCssExtractPlugin = require('mini-\/css-\/extract-\/plugin');}
\DoxyCodeLine{}
\DoxyCodeLine{module.exports = \{}
\DoxyCodeLine{  plugins: [}
\DoxyCodeLine{    new MiniCssExtractPlugin(\{}
\DoxyCodeLine{      moduleFilename: (\{ name \}) => `\$\{name.replace('/js/', '/css/')\}.css`,}
\DoxyCodeLine{    \}),}
\DoxyCodeLine{  ],}
\DoxyCodeLine{  module: \{}
\DoxyCodeLine{    rules: [}
\DoxyCodeLine{      \{}
\DoxyCodeLine{        test: /\(\backslash\).css\$/,}
\DoxyCodeLine{        use: [MiniCssExtractPlugin.loader, 'css-\/loader'],}
\DoxyCodeLine{      \},}
\DoxyCodeLine{    ],}
\DoxyCodeLine{  \},}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17585}{}\doxysubsubsection{Long Term Caching}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17585}
For long term caching use {\ttfamily filename\+: \char`\"{}\mbox{[}contenthash\mbox{]}.\+css\char`\"{}}. Optionally add {\ttfamily \mbox{[}name\mbox{]}}.

{\bfseries{webpack.\+config.\+js}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const MiniCssExtractPlugin = require('mini-\/css-\/extract-\/plugin');}
\DoxyCodeLine{}
\DoxyCodeLine{module.exports = \{}
\DoxyCodeLine{  plugins: [}
\DoxyCodeLine{    new MiniCssExtractPlugin(\{}
\DoxyCodeLine{      filename: '[name].[contenthash].css',}
\DoxyCodeLine{      chunkFilename: '[id].[contenthash].css',}
\DoxyCodeLine{    \}),}
\DoxyCodeLine{  ],}
\DoxyCodeLine{  module: \{}
\DoxyCodeLine{    rules: [}
\DoxyCodeLine{      \{}
\DoxyCodeLine{        test: /\(\backslash\).css\$/,}
\DoxyCodeLine{        use: [MiniCssExtractPlugin.loader, 'css-\/loader'],}
\DoxyCodeLine{      \},}
\DoxyCodeLine{    ],}
\DoxyCodeLine{  \},}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17586}{}\doxysubsubsection{Remove Order Warnings}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17586}
For projects where css ordering has been mitigated through consistent use of scoping or naming conventions, the css order warnings can be disabled by setting the ignore\+Order flag to true for the plugin.

{\bfseries{webpack.\+config.\+js}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const MiniCssExtractPlugin = require('mini-\/css-\/extract-\/plugin');}
\DoxyCodeLine{}
\DoxyCodeLine{module.exports = \{}
\DoxyCodeLine{  plugins: [}
\DoxyCodeLine{    new MiniCssExtractPlugin(\{}
\DoxyCodeLine{      ignoreOrder: true,}
\DoxyCodeLine{    \}),}
\DoxyCodeLine{  ],}
\DoxyCodeLine{  module: \{}
\DoxyCodeLine{    rules: [}
\DoxyCodeLine{      \{}
\DoxyCodeLine{        test: /\(\backslash\).css\$/i,}
\DoxyCodeLine{        use: [MiniCssExtractPlugin.loader, 'css-\/loader'],}
\DoxyCodeLine{      \},}
\DoxyCodeLine{    ],}
\DoxyCodeLine{  \},}
\DoxyCodeLine{\}; }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17587}{}\doxysubsubsection{Media Query Plugin}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17587}
If you\textquotesingle{}d like to extract the media queries from the extracted CSS (so mobile users don\textquotesingle{}t need to load desktop or tablet specific CSS anymore) you should use one of the following plugins\+:


\begin{DoxyItemize}
\item \href{https://github.com/SassNinja/media-query-plugin}{\texttt{ Media Query Plugin}}
\item \href{https://github.com/mike-diamond/media-query-splitting-plugin}{\texttt{ Media Query Splitting Plugin}}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17588}{}\doxysubsection{Contributing}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17588}
Please take a moment to read our contributing guidelines if you haven\textquotesingle{}t yet done so.

./.github/\+CONTRIBUTING.\+md \char`\"{}\+CONTRIBUTING\char`\"{}\hypertarget{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17589}{}\doxysubsection{License}\label{md_sfcode_node_modules_mini_css_extract_plugin_README_autotoc_md17589}
\href{./LICENSE}{\texttt{ MIT}} 