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
Cœur
  • 37,241
  • 25
  • 195
  • 267
Humberd
  • 2,794
  • 3
  • 20
  • 37

1 Answers1

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"]
},
Slawa Eremin
  • 5,264
  • 18
  • 28
  • 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? – Humberd Apr 26 '17 at 23:10
  • 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 – Slawa Eremin Apr 26 '17 at 23:14
  • Oh well, nevermind. I've just added the import statement to my index file and everything works as intended – Humberd Apr 26 '17 at 23:14