Giter VIP home page Giter VIP logo

Comments (9)

Sec-ant avatar Sec-ant commented on June 15, 2024 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.

fi3ework avatar fi3ework commented on June 15, 2024 1

虽然确保了antd组件样式不影响全局的,但是提高了antd样式的层级,导致后面如果要写自己的私有样式,一个类根本不够,会被antd的[class *=ant-]h1这种的覆盖掉

直接 !important

from blog.

a1ooha avatar a1ooha commented on June 15, 2024 1

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.

darknessjs avatar darknessjs commented on June 15, 2024

挂个私人链接:
https://www.yuque.com/zhongjing-tfizt/darkness/ihl4ef

from blog.

zhongweiming avatar zhongweiming commented on June 15, 2024

虽然确保了antd组件样式不影响全局的,但是提高了antd样式的层级,导致后面如果要写自己的私有样式,一个类根本不够,会被antd的[class *=ant-]h1这种的覆盖掉

from blog.

NameWjp avatar NameWjp commented on June 15, 2024

不错的方案,学习了

from blog.

PaperTiger7 avatar PaperTiger7 commented on June 15, 2024

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.

a1ooha avatar a1ooha commented on June 15, 2024

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.

csr632 avatar csr632 commented on June 15, 2024

我写了一个less插件来自动移除antd的全局样式antd/lib/style/core/global.lesshttps://github.com/csr632/less-plugin-remove-antd-global-styles
能够与vite, webpack, rollup以及babel-plugin-import一起使用。

from blog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.