scss

来源:3-6 【组件化】配置React的CSS模组

FanYiyang

2021-02-22

老师,请问下scss模块话也是一样的吗?

declare module "*.css" {
  const css: {[key: string]: string}
  export default css
}

可以在说下 const css: {[key: string]: string}是什么意思吗?必须要这样定义吗?

写回答

1回答

阿莱克斯刘

2021-02-24

因为Create-react-app脚手架没有原生支持scss,所以如果你得

1. 先安装scss的

$ npm install node-sass --save
$ # or
$ yarn add node-sass

2. import 你的 *.scss文件

@import 'styles/_colors.scss'; // assuming a styles directory under src/
@import '~nprogress/nprogress'; // importing a css file from the nprogress node module

3. 可以选择给项目配置SASS_PATH,如果有使用.env文件,可以在文件中加入下面的代码

SASS_PATH=node_modules:src

然后在引用scss文件的时候就可以不用写“~”符号了。

@import 'styles/colors'; // assuming a styles directory under src/, where _colors.scss partial file exists.
@import 'nprogress/nprogress'; // importing a css file from the nprogress node module


  • 官方文档参考(英文):

https://create-react-app.dev/docs/adding-a-sass-stylesheet/

0
1
FanYiyang
非常感谢!谢谢老师
2021-02-24
共1条回复

React18 系统精讲 结合TS打造旅游电商平台

React18 精讲 + 结合 TS 实战 + 热门业务开发,获取必备技能

1993 学习 · 1015 问题

查看课程