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