项目引入css文件后报错

Module build failed (from ./node_modules/_css-loader@2.1.1@css-loader/dist/cjs.js):
CssSyntaxError

(2:1) Unknown word

1 |
> 2 | var content = require("!!./index.css");
| ^
3 |
4 | if(typeof content === 'string') content = [[module.id, content, '']];

@ ./src/index.js 3:0-24

webpack.config.js代码:

module.exports = {
entry: './src/index.js',
output: {
// path.resolve解析当前相对路径的绝对路径 path.join
// path: path.resolve('./dist/'),
path: path.join(__dirname, './dist/'),
filename: 'bundle.js'
},
mode: 'development', // 默认production
// watch: true // 开启监视模式
devServer: {
open: true,
port: 8080,
compress: true,
hot: true
},
module: {
rules: [{
test: /\.css$/,
use: ['css-loader', 'style-loader']
}]
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: './src/index.html'
})
]
}

后来看了一下另一个项目,发现use的顺序放得不一样,修改为

module: {
rules: [{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}]
},

再次运行就可以了,

// webpack读取loader时,是从右到左
// loader执行顺序是从右到左以管道方式链式调用
// css-loader解析css文件,style-loader放到html文件

最新文章

  1. 微服务和SOA服务
  2. Ubuntu和Win双系统解决主板时间差
  3. angular+selecte2(angular ng-repeat渲染)
  4. SQL float 保留两位小数
  5. VPS 搭建 SS
  6. Flash与IE奇怪的关键字冲突
  7. [译]rabbitmq 2.1 Consumers and producers (not an economics lesson)
  8. python模拟http请求2
  9. error LNK2019: unresolved external symbol / error LNK2001: 无法解析的外部符号
  10. [原]Unity3D深入浅出 - 物理引擎之碰撞体(Colliders)
  11. CDR绘制绚丽五角星※※
  12. Ubuntu版本介绍
  13. VC中利用多线程技术实现线程之间的通信
  14. YII2 实现后台操作记录日志
  15. elicpse之tomcat配置
  16. idea自我使用简单使用方式和出现的一些简单问题以及常用快捷键
  17. 初学Python(第二课)
  18. 开源Spring解决方案--lm.solution
  19. ORACLE中使用row_number over()排序
  20. day37 异步回调和协程

热门文章

  1. FPGA实战操作(2) -- PCIe总线(例程设计分析)
  2. 一句话说明Facbook React证书的矛盾点
  3. pandas数据分析案例
  4. springboot2.0双数据源配置
  5. JAVA记事本的图形用户界面应用程序
  6. 算法之顺序、二分、hash查找
  7. shaderToy学习篇
  8. JavaScript参考DOM部分
  9. ElasticSearch - activemq - tomcat 开机自启动
  10. 论文阅读 | Towards a Robust Deep Neural Network in Text Domain A Survey