webpackcss-loadersass-loaderextracttextwebpackplugin

Cannot extract multiple scss files to one css file


It seems that I don't know the way how to extract multiple .scss files to a one .css file. After building my /dist folder constains only .js files. I followed many guides, but non of them works. Here is my webpack.config.js

module.exports = {
    entry: {
        index: ["./src/app/index.ts"],
        background: ["./src/background/background.ts"]
    },
    watch: true,
    watchOptions: {
        aggregateTimeout: 300,
        ignored: /node_modules/
    },
    output: {
        filename: "[name].js",
        path: path.resolve(__dirname, "dist")
    },
    module: {
        rules: [
            {
                test: /\.ts?$/,
                loader: "awesome-typescript-loader",
                exclude: [/\/node_modules\//]
            }, {
                test: /\.html$/,
                loader: "html-loader"
            }, {
                test: /\.scss$/,
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    //resolve-url-loader may be chained before sass-loader if necessary
                    use: ['css-loader', 'sass-loader']
                })
            }
        ]
    },
    plugins: [
        new CopyWebpackPlugin([
            {
                from: "manifest.json",
                to: "./"
            }, {
                from: "./node_modules/jquery/dist/jquery.js",
                to: "./"
            }
        ]),
        new ExtractTextPlugin('style.css'),
        new CleanWebpackPlugin("dist"),
    ],
    resolve: {
        extensions: [".ts", ".js"]
    }
};

@edit I have the newest modules:


Solution

  • Do you try this way?
    1) Create styles.scss that contain all scss imports that you need:

    2) create file: all-styles.js:

    import style1 from "./styles/styles.scss";

    3) Add all-styles.js as on of your entry point:

    entry: {
        index: ["./src/app/index.ts"],
        background: ["./src/background/background.ts"],
        styles: ["./src/all-styles.js"]
    },