webpack為什么加載不了css?


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

 

這個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)

  

 

解決:

原來test:'/\.css$/'這里寫錯了。
應該是test:/\.css$/ 不帶''

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM