Aaron Rabinowitz
Aaron Rabinowitz

Reputation: 357

webpack not getting seperate css file for extract text plugin

Hi everyone I am using web-pack to try to replace a gulp build that was overly complicated. but was running into some issues when it came to the Css. We are using sass. We also have a project structure that has the sass files right by each of the the angular component so that means for every class there is a separate folder. Currently our gulp magically goes into the folders and downloads the sass. But I can't get the extract-text-webpack-plugin to output me a separate Css file the source I am using for trying to do this is. https://itnext.io/sharing-sass-resources-with-sass-resources-loader-and-webpack-ca470cd11746

here is my code

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;

Any help would be much appreciated.

Upvotes: 0

Views: 32

Answers (0)

Related Questions