webpack没有获得单独的css文件以提取文本插件

时间:2018-12-10 19:36:28

标签: css webpack sass extracttextwebpackplugin

大家好,我正在使用Web Pack来替换过于复杂的gulp构建。但是在谈到CSS时遇到了一些问题。我们正在使用sass。我们还有一个项目结构,每个角度组件都具有sass文件,因此对于每个类都意味着有一个单独的文件夹。当前,我们的吞噬神奇地进入文件夹并且下载sass。 但是我无法获得extract-text-webpack-plugin来向我输出单独的Css文件,而我正在使用该文件来尝试执行此操作。 https://itnext.io/sharing-sass-resources-with-sass-resources-loader-and-webpack-ca470cd11746

这是我的代码

const config = {
    entry: {
        'app': './app/app.js',
        // 'vendor': './src/vendor.module.js'
    },
    devtool: 'source-map',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist/dev')
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: [ 'ng-annotate-loader', 'babel-loader' ]
            },
            // for fixing of loading bootstrap icon files
            {
                test: /\.(png|jpg|jpeg|gif|svg|woff|woff2)$/,
                loader: 'url-loader?limit=10000',
                options: {
                    name: './fonts/[name].[ext]'
                }
            },
            {
                test: /\.(eot|ttf)$/,
                loader: 'file-loader',
                options: {
                    name: './fonts/[name].[ext]'
                }
            },
            {
                test: /\.html$/,
                loader: 'html-loader',
                options: {
                    attrs: [ 'attrs=false' ]
                }
            },
            {
                test: /\.scss$/,
                use: ExtractTextWebpackPlugin.extract({
                    fallback: 'style-loader',
                    filename: path.resolve(__dirname, 'dist/dev') + 'app.css',
                    use: [
                        {
                            loader: 'style-loader'
                        },
                        {
                            loader: 'css-loader'
                        },
                        {
                            loader: 'sass-loader'
                        },
                        {
                            loader: 'sass-resources-loader',
                            options: {
                                resources: require(path.join(process.cwd(), './app/appscss.js'))
                            }
                        }
                    ]

                }),
            },







             /* ,
                {
                test: /\.(scss)$/,
                use: ExtractTextWebpackPlugin.extract({
                    use: [
                            {
                                loader: "css-loader",
                                options: {
                                    minimize: true
                                }
                            },
                            {
                                loader: "sass-loader"
                            }
                    ]
                })
            } */
        ]
    },
    plugins: [
        new webpack.optimize.UglifyJsPlugin({
            comments: false,
            sourceMap: true,
        }),

        new ExtractTextWebpackPlugin('app.css', {
            allChunks: true
        }),
        new webpack.DefinePlugin({
            GULP_REPLACE_ENV_URL: JSON.stringify(environementUrl())

        })
    ],
    devServer: {
        port: 5000,
        contentBase: path.resolve(__dirname, 'dist/dev'),
        historyApiFallback: true,
        // needed since we set api to something other than host
        // http://flummox-engineering.blogspot.com/2017/10/webpack-dev-server-invalid-host-header-host-0.0.0.0-not-working-npm-dev-server.html
        disableHostCheck: true
    }
};

module.exports = config;

任何帮助将不胜感激。

0 个答案:

没有答案
相关问题