我正在尝试导入我的 css 文件,但我一直收到此错误。 找不到模块“./style.css”
。我修改了我的 webpack.config.js
但没有成功。请任何指导或帮助表示赞赏。是的,Home.js 和 style.css 在同一个目录下。
webpack.config.js
...module: {
rules: [
{
test: /.js$/,
loader: 'babel-loader',
include: path.join(__dirname, 'app'),
exclude: /node_modules/,
query: {
presets: ['es2015', 'react', 'stage-1']
}
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
}
]
}...
样式.css
body {
background-color: #000000;
margin: 0px;
}
Home.js
import './style.css'
最佳答案
根据 doc这应该有效;
...module: {
rules: [
...
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader']
})
}
]
}...
关于javascript - 不能用 react/webpack 要求 css 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49622842/