简体   繁体   中英

Webpack error: You may need an appropriate loader to handle this file type. | @charset “UTF-8”;

I am trying to process a .scss file with Webpack 2.2.0 but instead of getting it injected into a style tag into my index.html file, I wanted to extract it into a .css file with ExtractTextPlugin.

The following is my webpack.config.js file:

// webpack.config.js

let path = require('path');
let ExtractTextPlugin = require('extract-text-webpack-plugin');
let extractCSS = new ExtractTextPlugin('[name].css');

module.exports = {
    context: path.resolve(__dirname, './src'),
    entry: './index.js',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'bundle.js',
        publicPath: 'dist/'
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                use: 'babel-loader',
            },
            {
                test: /\.(sass|scss)$/,
                use: [

                    ///////////////////////////////////////
                    // THIS WONT WORK AND CAUSES THE ERROR
                    ///////////////////////////////////////

                    extractCSS.extract({
                        fallbackLoader: 'style-loader',
                        loader: ['css-loader', 'sass-loader']
                    }),

                    /////////////
                    // THIS WORKS
                    /////////////

                    // 'style-loader', 'css-loader', 'sass-loader'
                ]
            },
            {
                test: /\.(eot|svg|ttf|woff|woff2)$/,
                loader: 'file-loader?name=[path][name].[ext]'
            }
        ]
    },
    plugins: [
        extractCSS
    ]
}

Any help is appreciated. Thanks.

This is a bug currently in ETP. I believe my switching use to "loader" that this will solve your problem. Module parse failed error for SCSS file .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM