webpack爲何加載不了css?

原文地址: https://segmentfault.com/q/1010000005099261javascript

 

這個app是用react寫的。css

webpack的loader設置是這樣的java

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

  

也安裝了css-loader, style-loadernode

但當加載css,import './stylesheets/all.css';
就會報錯:react

./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)

  

 

解決:webpack

原來test:'/\.css$/'這裏寫錯了。
應該是test:/\.css$/ 不帶''
相關文章
相關標籤/搜索