首页 > webpack为什么加载不了css?

webpack为什么加载不了css?

这个app是用react写的。

webpack的loader设置是这样的

module:{
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader:  'babel',
      },
      
      { 
        test: '/\.css$/', 
        loaders: ['style', 'css'],
        include: __dirname,
      },
    ],
  },

也安装了css-loader, style-loader

但当加载css,import './stylesheets/all.css';
就会报错:

./app/stylesheets/all.css
Module parse failed: D:\FrontEnd\mzFM-web\app\stylesheets\all.css Unexpected token (1:11)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (1:11)

求各位大神帮忙解答。

css长这样

html, body {
    margin: 0; 
    padding: 0;
    font-family: "Microsoft YaHei";
    font-size: 16px;
}


header {
    position: fixed; 
    top: 0;
    width: 100%;
    height: 2em;
}

https://github.com/webpack/style-loader
Recommended configuration:
loaders: ['style', 'css'] => loader: "style!css"


自问自答了。
原来test:'/\.css$/'这里写错了。
应该是test:/\.css$/ 不带''

【热门文章】
【热门文章】