0

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:

  • webpack: 2.4.1
  • sass-loader: 6.0.3
  • extract-text-webpack-plugin: 2.1.0

1 Answer 1

1

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"]
},

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, it works! But together with styles.css there is also created a styles.js file in my /dist directory. Do you know how to remove that js file?
webpack is a js-bundler, that's way you have js file too. In my project I have named all style files like*.style.css and have added *.style.js to .gitignore file. So I do not have junk in my repository
Oh well, nevermind. I've just added the import statement to my index file and everything works as intended

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.