(webpack打包css) You may need an appropriate loader to handle this file type

我在使用require("./style.css");的时候,也就是想要把css文件也一并打包,但是webpack本身是不支持的,所以我们需要安装

npm install css-loader style-loader --save-dev

安装成功

接下来指定loader

把 require("./style.css");改为:

require("css-loader!./style.css");//引用这个页面的时候,先经过css-loader处理

require("style-loader!css-loader!./style.css");
最后再重新打包就可以了


当然你也可以不在代码中添加style-loader!css-style!, 而是在打包过程中设置绑定依赖,如下命令

npx webpack a.js -o a.bundle.js --module-bind "css=style-loader!css-loader" --mode development    

注意: 是双引号.不是单引号...




猜你喜欢

转载自blog.csdn.net/lplife/article/details/80883115