webpack css-loader解析失败

时间:2018-07-08 03:08:08

标签: javascript css reactjs webpack webpack-style-loader

我正在使用webpack加载程序(css-loader / style-loader),但我不知道为什么下面的简单CSS代码会如此

body {
    background: blue;
} 

不断导致此错误,

ERROR in ./app/main.css 1:5
Module parse failed: Unexpected token (1:5)
You may need an appropriate loader to handle this file type.
> body {
    background: blue;
}
@ ./app/index.js 1:0-21

这是webpack.config.js的摘录

const Paths = {
    app: __dirname + '/app',
    build: __dirname + '/build',
};
module: {
        rules: [
        {
            test: /\.css&/,
            use: [{loader: 'style-loader'},
                  {loader: 'css-loader'}],
            include: Paths.app
        }]
    }

这是我的package.json代码段

"devDependencies": {
    "css-loader": "^1.0.0",
    "style-loader": "^0.21.0",
    "webpack": "^4.15.1",
    "webpack-cli": "^3.0.8"
  },

这是我第一次进行Webpack,css尝试,谢谢您的宝贵时间

1 个答案:

答案 0 :(得分:0)

您必须导入CSS。

添加const s = require('./main.css');index.js

让我知道您是否仍然遇到问题。