React的Sass配置


React提供的腳手架creact-react-app創建的工程文件不像vue那種暴露出webpack來,所以添加依賴需要拐個彎。

為了配置sass需要按以下步驟進行:

 一、安裝sass-loader和node-sass依賴

npm install sass-loader node-sass --save-dev

二、打開react的webpack配置

node_modules/react-scripts/config/webpack.config.js

找到module下的rules,oneof數組中,然后找到最后一個配置,修改成如下的樣子

 { loader: require.resolve('file-loader'), // Exclude `js` files to keep "css" loader working as it injects
              // its runtime that would otherwise be processed through "file" loader.
              // Also exclude `html` and `json` extensions so they get processed
              // by webpacks internal loaders.
              exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/], options: { name: 'static/media/[name].[hash:8].[ext]', }, }, // ** STOP ** Are you adding a new loader?
            // Make sure to add the new loader(s) before the "file" loader.
 { test:/\.scss$/, loaders: ['style-loader', 'css-loader', 'sass-loader'] }

    

 

 

三、這樣就可以愉快地使用scss文件了

 

 

 


免責聲明!

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



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