Getting css output using webpack ExtractTextPlugin

后端 未结 4 1384
轻奢々
轻奢々 2020-12-24 10:43

I am trying to get css requires to work in webpack using the ExtractTextPlugin but with no success

I want a separate css file rather than inlining any css.

4条回答
  •  猫巷女王i
    2020-12-24 11:19

    ExtractTextPlugin needs to be added in two spots: in the Loader, and as a Plugin. Here's the example pulled from the stylesheets documentation.

    // webpack.config.js
    var ExtractTextPlugin = require("extract-text-webpack-plugin");
    module.exports = {
        // The standard entry point and output config
        entry: {
            posts: "./posts",
            post: "./post",
            about: "./about"
        },
        output: {
            filename: "[name].js",
            chunkFilename: "[id].js"
        },
        module: {
            loaders: [
                // Extract css files
                {
                    test: /\.css$/,
                    loader: ExtractTextPlugin.extract("style-loader", "css-loader")
                },
                // Optionally extract less files
                // or any other compile-to-css language
                {
                    test: /\.less$/,
                    loader: ExtractTextPlugin.extract("style-loader", "css-loader!less-loader")
                }
                // You could also use other loaders the same way. I. e. the autoprefixer-loader
            ]
        },
        // Use the plugin to specify the resulting filename (and add needed behavior to the compiler)
        plugins: [
            new ExtractTextPlugin("[name].css")
        ]
    }
    

提交回复
热议问题