How do I get scss working with a react project?

久未见 提交于 2019-12-13 07:11:02

问题


For days I've been trying to set up a react project wether with react-create-app or my own webpack configuration that integrates scss in some way. I always get some weird dependency issue with wepack (can't find right version whether it be 2.2.1 or 1.4.1). Does anyone have an idea about how I would go about doing this?


回答1:


This is how I do it

package.json dependencies :

"css-loader": "^0.26.1",
"node-sass": "^4.4.0",
"sass-loader": "^4.1.1"

(or whatever the latest version are)

webpack.config.js module loaders :

{ 
    test: /\.scss$/, 
    loader: 'style-loader!css-loader!sass-loader'
}

inside your code (root file if possible)

import './<your style path>/<your style file>.scss'


来源:https://stackoverflow.com/questions/42677929/how-do-i-get-scss-working-with-a-react-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!