Dimples's blog Dimples's blog
首页
  • 前端随笔

    • React
  • 系列文章

    • 《ES6 教程》笔记
    • 《Vue》笔记
    • 《TypeScript》笔记
  • 后端文章

    • Java
    • Python
    • 数据库
  • 学习笔记

    • 《Rust》笔记
    • 《SpringBoot》笔记
    • 《Django》笔记
    • 《Docker》笔记
    • 《Python爬虫》笔记
技术分享
友情链接
索引
关于
GitHub (opens new window)

DimplesY

不会写代码
首页
  • 前端随笔

    • React
  • 系列文章

    • 《ES6 教程》笔记
    • 《Vue》笔记
    • 《TypeScript》笔记
  • 后端文章

    • Java
    • Python
    • 数据库
  • 学习笔记

    • 《Rust》笔记
    • 《SpringBoot》笔记
    • 《Django》笔记
    • 《Docker》笔记
    • 《Python爬虫》笔记
技术分享
友情链接
索引
关于
GitHub (opens new window)
  • React

    • 在React当中使用scss和按需加载antd
    • 使用Redux制作一个TodoList
    • React跨域配置
    • JS 当中的函数柯里化和高阶函数
    • useState的使用
  • 学习笔记

  • 前端
  • React
dimples
2020-11-20

在React当中使用scss和按需加载antd

# 在React当中使用scss

在实际的开发当中,因为css没有编程的特性,我们经常会选择富有编程特性的css预处理语言来编写css,scss就是其中的一种

在create-reacte-app的项目当中,使用淘宝镜像安装node-sass

npm i node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass
1

同时安装sass-loader,这里我使用yarn进行安装

yarn add sass-loader --dev
1

为了更好的使用scss的全局变量,可以让一个scss文件在构建的时候自动到项目当中,需要安装sass-resources-loader

yarn add sass-resources-loader --dev
1

全局配置如下:

配置webpack.config.js文件如下:

.concat({
    loader: 'sass-resources-loader',
    options: {
        resources: [
            path.resolve(__dirname, './../src/styles/main.scss')
        ]
    }
})
1
2
3
4
5
6
7
8

# 按需加载antd

安装完antd之后,进行如下配置

webpack.config.js文件如下:

['import', { libraryName: 'antd', style: 'css' }],
1
帮助我修改此页面 (opens new window)
上次更新: 2022/11/20, 18:28:09
使用Redux制作一个TodoList

使用Redux制作一个TodoList→

最近更新
01
使用 strapi 快速构建 API 和 CMS 管理系统
03-03
02
Rust 开发环境
11-26
03
使用 paka.dev 为 npm 包生成文档
11-24
更多文章>
Theme by Vdoing | Copyright © 2020-2025 Dimples YJ | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式