简体   繁体   English

将 webpack 用于 css 错误:模块解析失败

[英]using webpack for css Error:Module parse failed

I'm using Webpack in my project.我在我的项目中使用Webpack

webpack.config.js: webpack.config.js:

moule.exports ={
...
module:{
rules:[
{
test:/\.css$/,
use:[
{loader:"css-loader"}
{loader:"style-loader"}
]
}
...
]}

Everything except this works fine:除此以外的所有内容都可以正常工作:

css: css:

pre[class*="language-"]{
background:#f5f2f0
}

error:错误:

Module parse failed:Unexpected token (7:10)
You may need appropriate loader to handle this file type, currently no loaders are configured to process this file. see https://webpack.js.org/concepts#loaders 
*/
> pre[class*="language-"] {
background:#f5f2f0

can someone tell me what should I add in my webpack.config.js file to help the css file run?有人能告诉我应该在我的 webpack.config.js 文件中添加什么来帮助 css 文件运行吗?

change the use array in your webpack.config.js file towebpack.config.js文件中的use数组更改为

use: [
  "style-loader",
  "css-loader",
  "postcss-loader",
  },
]

Add a postcss.config file to your root folder with this content使用此内容将postcss.config文件添加到您的根文件夹

module.exports = {
    plugins: [require("precss"), require("autoprefixer")],
};

Specifically in this order.具体按这个顺序。

You can read more about postcss-loader here: https://webpack.js.org/loaders/postcss-loader/ Also, ensure you install these new loaders.您可以在此处阅读有关postcss-loader更多信息: https://webpack.js.org/loaders/postcss-loader/此外,请确保安装这些新的加载程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM