CssSyntaxError (2:1) Unknown word 1 | > 2 | var content = require("!!./index.css");
2024-09-02 17:56:22
项目引入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文件
最新文章
- 微服务和SOA服务
- Ubuntu和Win双系统解决主板时间差
- angular+selecte2(angular ng-repeat渲染)
- SQL float 保留两位小数
- VPS 搭建 SS
- Flash与IE奇怪的关键字冲突
- [译]rabbitmq 2.1 Consumers and producers (not an economics lesson)
- python模拟http请求2
- error LNK2019: unresolved external symbol / error LNK2001: 无法解析的外部符号
- [原]Unity3D深入浅出 - 物理引擎之碰撞体(Colliders)
- CDR绘制绚丽五角星※※
- Ubuntu版本介绍
- VC中利用多线程技术实现线程之间的通信
- YII2 实现后台操作记录日志
- elicpse之tomcat配置
- idea自我使用简单使用方式和出现的一些简单问题以及常用快捷键
- 初学Python(第二课)
- 开源Spring解决方案--lm.solution
- ORACLE中使用row_number over()排序
- day37 异步回调和协程