Add SCSS config for old React project.
My React app was created by create-react-app
1.3.1 about five years ago.
I have to change the Node verstion to 8.9.4 every time when I want to run it locally.
The app has both .scss files
and .css files
which were compiled by relevant scss files. And in components, we imported the CSS file.
So I always want to find a way to import the SCSS file directly.
Today I have made it done.
First, install node-sass
and sass-loader
1 | "node-sass": "^4.5.3", |
As above config, I have to install the specific version for my old project.
Then add a rule for SCSS file in webpack.config.dev.js
1 | { |
Before you serve your project, don’t forget to add .scss
extension to loader exclusion list
1 | { |
Now you can import SCSS file in components, and run start script
to see the result.
1 | import '../index.scss' |
原文作者: dgb8901,yinxing
原文链接: https://www.itwork.club/2022/01/25/Add-SCSS-config-for-old-React-project/
版权声明: 转载请注明出处
为您推荐
体验小程序「简易记账」
关注公众号「特想学英语」