Comments (9)
这样做好像 html 和 body 标签下的样式无法指定,主要影响的是 font,antd 的会被全局样式所覆盖。不过如果这点不重要的话,其他样式看起来的都是没什么问题的,感谢提供的方案。
多说一句,antd 4.7.0 里面不再是 base.less 设定全局样式,所有的全局样式都移动到了 global.less 这个文件里,base.less 已经限定了作用域,所以如果要改写 antd.less 的话,需要改成如下内容:
@import '~antd/lib/style/themes/index.less';
@import '~antd/lib/style/mixins/index.less';
*[class*='ant-'] {
@import '~antd/lib/style/core/global.less';
}
@import '~antd/lib/style/core/base.less';
@import '~antd/lib/style/core/iconfont.less';
@import '~antd/lib/style/core/motion.less';
@import '~antd/lib/style/components.less';
from blog.
虽然确保了antd组件样式不影响全局的,但是提高了antd样式的层级,导致后面如果要写自己的私有样式,一个类根本不够,会被antd的[class *=ant-]h1这种的覆盖掉
直接 !important
from blog.
用 patch-package
打个补丁,直接将 node_modules/antd/lib/style/core/index.less
改成下面这样就行:
@import '../mixins/index';
@import 'base';
*[class*='ant-'] {
@import 'global';
}
@import 'iconfont';
@import 'motion';
步骤少,很方便。
from blog.
挂个私人链接:
https://www.yuque.com/zhongjing-tfizt/darkness/ihl4ef
from blog.
虽然确保了antd组件样式不影响全局的,但是提高了antd样式的层级,导致后面如果要写自己的私有样式,一个类根本不够,会被antd的[class *=ant-]h1这种的覆盖掉
from blog.
不错的方案,学习了
from blog.
用
patch-package
打个补丁,直接将node_modules/antd/lib/style/core/index.less
改成下面这样就行:@import '../mixins/index'; @import 'base'; *[class*='ant-'] { @import 'global'; } @import 'iconfont'; @import 'motion';
步骤少,很方便。
兄弟,试了下,不行呀,和antd版本有关系吗?
from blog.
用
patch-package
打个补丁,直接将node_modules/antd/lib/style/core/index.less
改成下面这样就行:@import '../mixins/index'; @import 'base'; *[class*='ant-'] { @import 'global'; } @import 'iconfont'; @import 'motion';
步骤少,很方便。
兄弟,试了下,不行呀,和antd版本有关系吗?
应该没关系,你按照 patch-package 的文档操作,生成 patches 文件夹及对应的文件了吗?
from blog.
我写了一个less插件来自动移除antd的全局样式antd/lib/style/core/global.less
: https://github.com/csr632/less-plugin-remove-antd-global-styles
能够与vite, webpack, rollup以及babel-plugin-import一起使用。
from blog.
Related Issues (20)
- 设计模式之「结构型模式」 HOT 1
- 设计模式之「行为型模式」 HOT 3
- 分析生产环境的 Promise 实现,完整理解 Promise 原理
- 跟着 Event loop 规范理解浏览器中的异步机制 HOT 20
- _deprecated
- 简要分析前端代码从 Babel 编译到打包的流程
- [译] 资源提示 —— 什么是 Preload,Prefetch 和 Preconnect? HOT 4
- [译] Prefetch & preconnect-dns 的优先级 HOT 3
- 从一个极简 Node 服务器的实现中能学到什么?
- 浅谈 HTTP 缓存实践 HOT 3
- LazyMan 有几样写法,你知道么? HOT 4
- 浅析 React v16.3 新生命周期函数 HOT 1
- create-react-app 原理及源码分析 HOT 2
- Webpack 中 path/publicPath/contentBase 的关系 HOT 1
- koa2 源码及流程分析 HOT 1
- Knowledge fragment
- Knowledge fragment
- Knowledge fragment
- 不准备继续翻译了么
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.