A
A
alaskafx2022-01-28 19:35:40
webpack
alaskafx, 2022-01-28 19:35:40

How to force webpack to render styles as .css and not .js?

I have webpack settings like this:

const path = require('path')
const HTMLWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

module.exports = {
    context: path.resolve(__dirname, 'src'),
    mode: 'development',
    module:{
        rules: [
            {
                test: /\.css$/i,
                use: [MiniCssExtractPlugin.loader, "css-loader"],
            },
            {
                test: /\.html$/i,
                loader: "html-loader",
            },
            // Правила для стилей
            { test: /\.txt$/, use: 'raw-loader' },
            {
                test: /\.scss$/,
                use: [
                    "style-loader", // 3. Inject styles into DOM
                    "css-loader", // 2. Turns css into commonjs
                    "sass-loader", // 1. Turns sass into css
                ],
            },
        ]
    },
    entry: {
        app:[
            path.resolve(__dirname, './src/index.html'),
            path.resolve(__dirname, './src/assets/styles/style.scss'),
            path.resolve(__dirname, './src/assets/styles/reset.scss')
        ]
    },
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'js/[name].js'
    },
    plugins: [
        new HTMLWebpackPlugin({
            template: "./index.html",
            title: 'DIGITAL'
        }),
        new CleanWebpackPlugin(),
        new MiniCssExtractPlugin()
    ]
}


In my case, when npm run build webpack builds index.html and app.js and nothing else.
I need webpack to create a separate styles folder and put all my .css files there. How to implement it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2022-01-28
@bingo347

"style-loader", // 3. Inject styles into DOM
should be here tooMiniCssExtractPlugin.loader

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question