window not defined error when using extract-text-webpack-plugin React

前端 未结 4 945
闹比i
闹比i 2020-12-13 01:21

I\'m using webpack to build my react components and I\'m trying to use the extract-text-webpack-plugin to separate my css from my generated js file. However, wh

4条回答
  •  醉梦人生
    2020-12-13 02:08

    Webpack 2

    If you're using Webpack 2, this variation works:

        rules: [{
            test: /\.css$/,
            exclude: '/node_modules/',
            use: ExtractTextPlugin.extract({
                fallback: [{
                    loader: 'style-loader',
                }],
                use: [{
                    loader: 'css-loader',
                    options: {
                        modules: true,
                        localIdentName: '[name]__[local]--[hash:base64:5]',
                    },
                }, {
                    loader: 'postcss-loader',
                }],
            }),
        }]
    

    The new extract method no longer takes three arguments, and is listed as a breaking change when moving from V1 to V2.

    https://webpack.js.org/guides/migrating/#extracttextwebpackplugin-breaking-change

提交回复
热议问题