{"id":215,"date":"2026-08-30T23:20:09","date_gmt":"2026-08-30T15:20:09","guid":{"rendered":"http:\/\/www.fcsteeltech.com\/blog\/?p=215"},"modified":"2026-08-30T23:20:09","modified_gmt":"2026-08-30T15:20:09","slug":"how-do-i-use-a-mini-css-extract-plugin-loader-in-webpack-4640-9b89f6","status":"publish","type":"post","link":"http:\/\/www.fcsteeltech.com\/blog\/2026\/08\/30\/how-do-i-use-a-mini-css-extract-plugin-loader-in-webpack-4640-9b89f6\/","title":{"rendered":"How do I use a mini &#8211; css &#8211; extract &#8211; plugin Loader in webpack?"},"content":{"rendered":"<p>As a well &#8211; established loader provider in the web development industry, I&#8217;m often approached by developers and webmasters regarding the effective use of various loaders in webpack. One of the frequently asked questions is about the mini &#8211; css &#8211; extract &#8211; plugin loader. In this blog post, I&#8217;ll share my in &#8211; depth knowledge and experiences on how to use the mini &#8211; css &#8211; extract &#8211; plugin loader in webpack, which will hopefully help you optimize your web projects. <a href=\"https:\/\/www.shandongfeisite.com\/loader\/\">Loader<\/a><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.shandongfeisite.com\/uploads\/47088\/small\/construction-wheel-loader480e6.jpg\"><\/p>\n<h3>Understanding the Mini &#8211; CSS &#8211; Extract &#8211; Plugin Loader<\/h3>\n<p>Before diving into the usage details, it&#8217;s essential to understand what the mini &#8211; css &#8211; extract &#8211; plugin loader is and why it&#8217;s important. The mini &#8211; css &#8211; extract &#8211; plugin is a webpack plugin that extracts CSS into separate files. It creates a CSS file per JS file which contains CSS. This is a significant improvement over the previous approach of injecting CSS into the DOM using style &#8211; loader, especially for production builds.<\/p>\n<p>The loader part of it is responsible for handling the CSS files and preparing them to be extracted by the plugin. It allows webpack to recognize and process CSS files as part of the build process.<\/p>\n<h3>Prerequisites<\/h3>\n<p>To use the mini &#8211; css &#8211; extract &#8211; plugin loader, you first need to have a basic webpack project set up. This involves having Node.js and npm (Node Package Manager) installed on your system. You&#8217;ll also need to have webpack and webpack &#8211; cli installed in your project directory. You can install them using the following commands:<\/p>\n<pre><code class=\"language-bash\">npm init -y\nnpm install webpack webpack - cli --save - dev\n<\/code><\/pre>\n<p>Once you have the basic webpack setup, you can install the mini &#8211; css &#8211; extract &#8211; plugin and its associated loader:<\/p>\n<pre><code class=\"language-bash\">npm install mini - css - extract - plugin --save - dev\n<\/code><\/pre>\n<h3>Configuration in Webpack<\/h3>\n<p>The next step is to configure the mini &#8211; css &#8211; extract &#8211; plugin loader in your webpack configuration file (usually named <code>webpack.config.js<\/code>).<\/p>\n<p>Here&#8217;s a basic example of a webpack configuration with the mini &#8211; css &#8211; extract &#8211; plugin:<\/p>\n<pre><code class=\"language-javascript\">const MiniCssExtractPlugin = require('mini - css - extract - plugin');\n\nmodule.exports = {\n    entry: '.\/src\/index.js',\n    output: {\n        path: __dirname + '\/dist',\n        filename: 'bundle.js'\n    },\n    module: {\n        rules: [\n            {\n                test: \/\\.css$\/,\n                use: [\n                    MiniCssExtractPlugin.loader,\n                    'css - loader'\n                ]\n            }\n        ]\n    },\n    plugins: [\n        new MiniCssExtractPlugin({\n            filename: '[name].css',\n            chunkFilename: '[id].css'\n        })\n    ]\n};\n<\/code><\/pre>\n<p>In this configuration:<\/p>\n<ul>\n<li><strong>Entry<\/strong>: Specifies the entry point of your application. In this case, it&#8217;s <code>.\/src\/index.js<\/code>.<\/li>\n<li><strong>Output<\/strong>: Defines where the bundled files will be saved. The JavaScript bundle will be saved as <code>bundle.js<\/code> in the <code>dist<\/code> directory.<\/li>\n<li><strong>Module Rules<\/strong>: Here, we define a rule for handling CSS files. The <code>test<\/code> property uses a regular expression to match all files with the <code>.css<\/code> extension. The <code>use<\/code> property is an array that specifies the loaders to be used. We first use the <code>MiniCssExtractPlugin.loader<\/code> to extract the CSS into separate files, and then the <code>css - loader<\/code> to interpret <code>@import<\/code> and <code>url()<\/code> like <code>import\/require()<\/code> and resolve them.<\/li>\n<li><strong>Plugins<\/strong>: We initialize the <code>MiniCssExtractPlugin<\/code> with some options. The <code>filename<\/code> option determines the name of the output CSS file, and the <code>chunkFilename<\/code> option is for the name of the CSS file for dynamic imports.<\/li>\n<\/ul>\n<h3>Advanced Configuration<\/h3>\n<h4>Handling Multiple CSS Sources<\/h4>\n<p>In real &#8211; world projects, you may have multiple CSS sources, such as third &#8211; party libraries and your own custom stylesheets. You can handle them in different ways.<\/p>\n<p>For example, if you want to apply different configurations to different CSS sources, you can use multiple rules in the <code>module.rules<\/code> section:<\/p>\n<pre><code class=\"language-javascript\">module.exports = {\n    \/\/... other configuration\n    module: {\n        rules: [\n            {\n                test: \/\\.css$\/,\n                exclude: \/node_modules\/,\n                use: [\n                    MiniCssExtractPlugin.loader,\n                    {\n                        loader: 'css - loader',\n                        options: {\n                            importLoaders: 1,\n                            modules: true\n                        }\n                    },\n                    'postcss - loader'\n                ]\n            },\n            {\n                test: \/\\.css$\/,\n                include: \/node_modules\/,\n                use: [\n                    MiniCssExtractPlugin.loader,\n                    'css - loader'\n                ]\n            }\n        ]\n    },\n    \/\/... other configuration\n};\n<\/code><\/pre>\n<p>In this setup, we have two rules for CSS files. The first rule excludes CSS files from the <code>node_modules<\/code> directory and applies <code>css - loader<\/code> with module support and <code>postcss - loader<\/code>. The second rule includes only CSS files from the <code>node_modules<\/code> directory and simply uses the basic <code>css - loader<\/code>.<\/p>\n<h4>Combining with Other Loaders<\/h4>\n<p>The mini &#8211; css &#8211; extract &#8211; plugin loader can be combined with other loaders to achieve more complex functionality. For instance, if you want to use Sass in your project, you can add the <code>sass - loader<\/code> to the loader chain:<\/p>\n<pre><code class=\"language-javascript\">module.exports = {\n    \/\/... other configuration\n    module: {\n        rules: [\n            {\n                test: \/\\.(scss|sass)$\/,\n                use: [\n                    MiniCssExtractPlugin.loader,\n                    'css - loader',\n                    'sass - loader'\n                ]\n            }\n        ]\n    },\n    \/\/... other configuration\n};\n<\/code><\/pre>\n<p>This configuration allows you to write your styles in Sass files, which will be compiled to CSS and then extracted into separate files.<\/p>\n<h3>Production and Development Considerations<\/h3>\n<h4>Production<\/h4>\n<p>In a production environment, you&#8217;ll want to optimize the CSS output. You can use tools like <code>optimize - css - assets - webpack - plugin<\/code> to minify the CSS files. Here&#8217;s how you can integrate it with the mini &#8211; css &#8211; extract &#8211; plugin:<\/p>\n<pre><code class=\"language-bash\">npm install optimize - css - assets - webpack - plugin --save - dev\n<\/code><\/pre>\n<pre><code class=\"language-javascript\">const MiniCssExtractPlugin = require('mini - css - extract - plugin');\nconst OptimizeCSSAssetsPlugin = require('optimize - css - assets - webpack - plugin');\n\nmodule.exports = {\n    \/\/... other configuration\n    optimization: {\n        minimizer: [\n            new OptimizeCSSAssetsPlugin({})\n        ]\n    },\n    plugins: [\n        new MiniCssExtractPlugin({\n            filename: '[name].[contenthash].css',\n            chunkFilename: '[id].[contenthash].css'\n        })\n    ]\n};\n<\/code><\/pre>\n<p>The <code>optimize - css - assets - webpack - plugin<\/code> will minify the CSS files, and we&#8217;ve also added the <code>contenthash<\/code> to the filenames. This ensures that the browser cache is busted when the CSS content changes.<\/p>\n<h4>Development<\/h4>\n<p>In a development environment, you may want to have faster builds and easier debugging. One approach is to use the <code>style - loader<\/code> instead of the <code>MiniCssExtractPlugin.loader<\/code> during development. You can create separate webpack configurations for development and production:<\/p>\n<p><strong>webpack.dev.js<\/strong>:<\/p>\n<pre><code class=\"language-javascript\">const path = require('path');\n\nmodule.exports = {\n    entry: '.\/src\/index.js',\n    output: {\n        path: path.resolve(__dirname, 'dist'),\n        filename: 'bundle.js'\n    },\n    module: {\n        rules: [\n            {\n                test: \/\\.css$\/,\n                use: [\n                    'style - loader',\n                    'css - loader'\n                ]\n            }\n        ]\n    }\n};\n<\/code><\/pre>\n<p><strong>webpack.prod.js<\/strong>:<\/p>\n<pre><code class=\"language-javascript\">const MiniCssExtractPlugin = require('mini - css - extract - plugin');\nconst OptimizeCSSAssetsPlugin = require('optimize - css - assets - webpack - plugin');\n\nmodule.exports = {\n    entry: '.\/src\/index.js',\n    output: {\n        path: __dirname + '\/dist',\n        filename: 'bundle.js'\n    },\n    module: {\n        rules: [\n            {\n                test: \/\\.css$\/,\n                use: [\n                    MiniCssExtractPlugin.loader,\n                    'css - loader'\n                ]\n            }\n        ]\n    },\n    optimization: {\n        minimizer: [\n            new OptimizeCSSAssetsPlugin({})\n        ]\n    },\n    plugins: [\n        new MiniCssExtractPlugin({\n            filename: '[name].[contenthash].css',\n            chunkFilename: '[id].[contenthash].css'\n        })\n    ]\n};\n<\/code><\/pre>\n<p>You can then run the appropriate configuration using the following commands:<\/p>\n<pre><code class=\"language-bash\">npx webpack --config webpack.dev.js\nnpx webpack --config webpack.prod.js\n<\/code><\/pre>\n<h3>Conclusion and Call to Action<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/www.shandongfeisite.com\/uploads\/47088\/small\/construction-loaders9dc41.jpg\"><\/p>\n<p>The mini &#8211; css &#8211; extract &#8211; plugin loader is a powerful tool in the webpack ecosystem that can significantly improve the performance and maintainability of your web projects. By carefully configuring it and combining it with other loaders, you can achieve optimal results in both development and production environments.<\/p>\n<p><a href=\"https:\/\/www.shandongfeisite.com\/loader\/wheel-loader\/\">Wheel Loader<\/a> As a loader provider, I have extensive experience in helping businesses and developers optimize their webpack configurations. If you&#8217;re facing challenges with using the mini &#8211; css &#8211; extract &#8211; plugin loader or any other loaders, I&#8217;m here to assist you. Whether it&#8217;s customizing the configuration, integrating with other tools, or optimizing for performance, I can provide expert solutions tailored to your needs. Don&#8217;t hesitate to contact me for a free consultation and let&#8217;s discuss how we can enhance your web development projects.<\/p>\n<h3>References<\/h3>\n<ul>\n<li>Webpack official documentation<\/li>\n<li>Mini &#8211; CSS &#8211; Extract &#8211; Plugin official GitHub repository<\/li>\n<li>Various web development blogs and forums<\/li>\n<\/ul>\n<hr>\n<p><a href=\"https:\/\/www.shandongfeisite.com\/\">Shandong Feisite Machinery Co., Ltd.<\/a><br \/>As one of the most professional loader manufacturers and suppliers in China, we&#8217;re featured by quality products and good service. Please rest assured to buy cheap loader made in China here and get quotation from our factory. Customized orders are welcome.<br \/>Address: 100 meters south of Zengfusi Village, Mihe Town, Qingzhou City, Shandong Province<br \/>E-mail: Wpeng19911103@qq.com<br \/>WebSite: <a href=\"https:\/\/www.shandongfeisite.com\/\">https:\/\/www.shandongfeisite.com\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a well &#8211; established loader provider in the web development industry, I&#8217;m often approached by &hellip; <a title=\"How do I use a mini &#8211; css &#8211; extract &#8211; plugin Loader in webpack?\" class=\"hm-read-more\" href=\"http:\/\/www.fcsteeltech.com\/blog\/2026\/08\/30\/how-do-i-use-a-mini-css-extract-plugin-loader-in-webpack-4640-9b89f6\/\"><span class=\"screen-reader-text\">How do I use a mini &#8211; css &#8211; extract &#8211; plugin Loader in webpack?<\/span>Read more<\/a><\/p>\n","protected":false},"author":130,"featured_media":215,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[178],"class_list":["post-215","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-industry","tag-loader-435a-9c463b"],"_links":{"self":[{"href":"http:\/\/www.fcsteeltech.com\/blog\/wp-json\/wp\/v2\/posts\/215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.fcsteeltech.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.fcsteeltech.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.fcsteeltech.com\/blog\/wp-json\/wp\/v2\/users\/130"}],"replies":[{"embeddable":true,"href":"http:\/\/www.fcsteeltech.com\/blog\/wp-json\/wp\/v2\/comments?post=215"}],"version-history":[{"count":0,"href":"http:\/\/www.fcsteeltech.com\/blog\/wp-json\/wp\/v2\/posts\/215\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.fcsteeltech.com\/blog\/wp-json\/wp\/v2\/posts\/215"}],"wp:attachment":[{"href":"http:\/\/www.fcsteeltech.com\/blog\/wp-json\/wp\/v2\/media?parent=215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.fcsteeltech.com\/blog\/wp-json\/wp\/v2\/categories?post=215"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.fcsteeltech.com\/blog\/wp-json\/wp\/v2\/tags?post=215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}