javascript - Webpack 错误 : You may need an appropriate loader to handle this file type. | @字符集 "UTF-8";

标签 javascript css utf-8 sass webpack

我正在尝试使用 Webpack 2.2.0 处理一个 .scss 文件,而不是将它注入(inject)到我的 index.html< 中的 style 标签中 文件,我想用 ExtractTextPlugin 将它提取到 .css 文件中。

以下是我的webpack.config.js文件:

// 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
    ]
}

感谢任何帮助。谢谢。

最佳答案

这是目前 ETP 中的一个错误。我相信我切换到“加载器”,这将解决您的问题。 Module parse failed error for SCSS file .

关于javascript - Webpack 错误 : You may need an appropriate loader to handle this file type. | @字符集 "UTF-8";,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41754249/

相关文章:

css - Bootstrap 表固定 header colspan 不起作用

css - 为什么 !important 在我的 CSS 中不起作用?

php - UTF-8贯穿始终

javascript - AngularJS - 文本字段完成后调用函数

javascript - 在 Angular 应用程序中使用 HTML 设置 JSON 样式

html - 在 Google 协作平台中垂直对齐文本

java - 使用ByteStream读取UTF-8字符

mysql - 在 MySQL 中更改字符集

javascript/jQuery 数组串联?

javascript - 计算不包括节假日和周末的 future 日期