webpack 无法解析“样式" [英] webpack Can't resolve 'style'
问题描述
我试图从 (http://webpack.github.io/docs/tutorials/getting-started/).当我尝试加载 style.css 时出现此错误.
I was trying to follow the simple Getting Started from (http://webpack.github.io/docs/tutorials/getting-started/). And I am getting this error when I try to load style.css.
./entry.js 中的错误找不到模块:错误:无法解析我的计算机中的项目路径"中的样式"突破性变化:在使用加载器时不再允许省略-loader"后缀.您需要指定 'style-loader' 而不是 'style'.@ ./entry.js 1:0-22
ERROR in ./entry.js Module not found: Error: Can't resolve 'style' in 'Path to project in my computer' BREAKING CHANGE: It's no longer allowed to omit the '-loader' suffix when using loaders. You need to specify 'style-loader' instead of 'style'. @ ./entry.js 1:0-22
有什么想法吗?
如教程中所述,我使用 mpm 在本地安装了 css-loader 和 style-loader.npm install css-loader 样式加载器
I installed css-loader and style-loader locally using mpm as explained in tutorial. npm install css-loader style-loader
我看到安装后创建的 node-modules 文件夹.
I see node-modules folder created after the installation.
推荐答案
For webpack version >=2.0
For webpack version >=2.0
更新webpack.config.js
module.exports = {
entry: "./entry.js",
output: {
path: __dirname,
filename: "bundle.js"
},
module: {
loaders: [
{ test: /\.css$/, loader: "style-loader!css-loader" }
]
}
};
使用 { test:/.css$/, loader: "style-loader!css-loader" } 而不是 { test:/.css$/, loader: "style!css!"}
Use { test: /.css$/, loader: "style-loader!css-loader" } instead of { test: /.css$/, loader: "style!css!" }
这篇关于webpack 无法解析“样式"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!