A
A
AfterGen2019-10-19 14:30:02
webpack
AfterGen, 2019-10-19 14:30:02

How to properly process css file in webpack 4 loader + mini-extract-css-plugin?

There is a simple config for webpack 4

const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
    entry: {
        app: './src/index.js',
    },
    output: {
        filename: '[name].js',
        path: path.resolve(__dirname, './dist'),
        publicPath: '/dist',
    },
    plugins: [
        new MiniCssExtractPlugin({
            filename: '[name].css',
        })
    ],
    module: {
        rules: [
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: '/node_modules/'
            },
            {
                test: /\.css$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    'css-loader'
                ],
            },
        ],
    },
    devServer: {
        overlay: true,
    },
}

The css file is imported into the entry point (index.js), it is necessary to output it in the production assembly to a separate main.css file (using the mini-css-extract-plugin). But there is an error
mVdcp_8DQ4qtQqEb4gaqcw.png
Here is the complete file structure

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question