我在尝试捆绑我的 React 应用程序时遇到错误。
Uncaught Error: Module build failed (from ./node_modules/css-loader/index.js): ModuleParseError: Module parse failed: Unexpected character ' '
./src/static/css/main.css Module build failed (from ./node_modules/css-loader/index.js): ModuleParseError: Module parse failed: Unexpected character ' '
./src/static/fonts/CHILLER.TTF 1:0 Module parse failed: Unexpected character ' '
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
module: {
rules: [
{
test: /\.(png|jp?g|svg)(\?v=\d+\.\d+\.\d+)?$/,
use : [{
loader: 'file-loader',
options: {
name: '[name].[ext]'
}}
]
},
{
test: /\.(woff|woff2|eot|ttf)?$/,
loader: 'file-loader',
options: {
name: "[name].[ext]"
}
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "css-loader"
})
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
filename: './index.html'
}),
new ExtractTextPlugin('style.css')
]
}
最佳答案
您需要适当的加载器来加载不同的文件类型。 对于 CSS,你可以只使用 css-loader 和 style-loader。 这是 CSS 加载的工作示例 https://www.codeqna.com/2018/06/working-with-webpack-4-and-npm.html
关于Webpack 4 - 模块解析失败 : Unexpected character ' ' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50927674/