I
I
Ivan2020-01-08 21:39:35
webpack
Ivan, 2020-01-08 21:39:35

Why doesn't webpack compile sass to css and put it in dist?

const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ImageminPlugin = require("imagemin-webpack");

module.exports = {
    devtool: "source-map",
    entry: "./src/index.js",
    output: {
        path: path.resolve(__dirname, "dist"),
        filename: "bundle.js",
        publicPath: "/"
    },

    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: "babel-loader"
                },
            },
            {
                test: /\.(sass|scss)$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    {
                        loader: "css-loader",
                        options: {
                            sourceMap: true,
                            minimize: true,
                            url: false
                        }
                    },
                    // 'postcss-loader',
                    {
                        loader: "sass-loader",
                        options: {
                            sourceMap: true
                        }
                    }

                ],
            },
        ]
    },
    plugins: [
        new MiniCssExtractPlugin({
            filename: "[name].css",
            chunkFilename: "[id].css"
        }),
        new HtmlWebpackPlugin({
            template: "./src/index.html"
        }),
    ],

    resolve: {
        extensions: ['.js', '.scss', '.sass']
    },
    devServer: {
        overlay: true
    },
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2020-01-09
@BenderIsGreat34

Option 1: do import sass from js Option 2: write sass file as 1 more entry in webpack:import './main.sass';

module.exports = {
    devtool: "source-map",
    entry: ["./src/main.sass", "./src/index.js"],
    // ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question