A less plugin that removes ant-design global styles

Overview

less-plugin-remove-antd-global-styles

This is a less plugin that removes ant-design global styles.

It works well with vite, webpack, rollup and babel-plugin-import.

Solve ant-design/ant-design#9363 .

How it works

It works by mapping the global.less into an empty file: https://github.com/csr632/less-plugin-remove-antd-global-styles/blob/main/src/index.ts

Usage

npm i -D less-plugin-remove-antd-global-styles

vite

If you are using vite, pass it to vite config:

// vite.config.ts
import { LessPluginRemoveAntdGlobalStyles } from 'less-plugin-remove-antd-global-styles'

export default {
  // ...
  css: {
    preprocessorOptions: {
      less: {
        // put less plugin here
        plugins: [new LessPluginRemoveAntdGlobalStyles()],
      },
    },
  },
}

webpack

If you are using webpack, pass it to less-loader options:

// webpack.config.js
const { LessPluginRemoveAntdGlobalStyles } = require('less-plugin-remove-antd-global-styles');

module.exports = {
  ...
    {
      loader: 'less-loader',
      options: {
        lessOptions: {
          plugins: [
            new LessPluginRemoveAntdGlobalStyles(),
          ],
          javascriptEnabled: true,
        },
      },
    },
  ...
};

Stackblitz demo: https://stackblitz.com/edit/webpack-5-react-starter-exaaw5?file=webpack.config.js

rollup

If you are using rollup, pass it to rollup-plugin-postcss:

// rollup.config.js
import { LessPluginRemoveAntdGlobalStyles } from 'less-plugin-remove-antd-global-styles'

export default {
  plugins: [
    postcss({
      use: {
        less: {
          plugins: [new LessPluginRemoveAntdGlobalStyles()],
        },
      },
    }),
  ],
}

babel-plugin-import

If you are using babel-plugin-import to do import-on-demand, you should pass style: true to the babel plugin (so that it will import .less files instead of .css files). Here is a babel.config.json example:

{
  "plugins": [
    [
      "babel-plugin-import",
      {
        "libraryName": "antd",
        "style": true
      }
    ]
  ]
}

Tips

You may want to add some reasonable global styles to your own stylesheet after removing global styles from antd. For example, you probably want to keep these styles:

/* your-own-global-style.less  */

/* 
pick some reasonable global styles from
https://github.com/ant-design/ant-design/blob/master/components/style/core/global.less
*/

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* you can make reset styles only take effect within antd elements */
*[class*='ant-'] {
  a {
    text-decoration: none;
  }
}
You might also like...

It's a set of common utility strategies to work with responsive styles with Flutter and CSS in JS

It's a set of common utility strategies to work with responsive styles with Flutter and CSS in JS

@skynexui/responsive_stylesheet You don't need to be worried just because you have to support multiple screens 📺 🖥 💻 📱 It's a set of common utilit

Oct 26, 2022

A drop-in collection of CSS styles to make simple websites just a little nicer

Water.css 🌊 A drop-in collection of CSS styles to make simple websites just a little nicer Goals Responsive Themeable Good browser support (works on

Jan 4, 2023

Convert Tailwind CSS class names into their CSS3-equivalent styles — right from Alfred.

alfred-tailwind2css Tailwind2CSS offers you the ability to convert TailwindCSS classes into their CSS3-equivalent styles -- right from within Alfred.

Dec 7, 2022

Solid.js library adding a services layer for global shared state.

Solid.js library adding a services layer for global shared state.

Solid Services Services are "global" objects useful for features that require shared state or persistent connections. Example uses of services might i

Dec 30, 2022

An event emitter that allows you to manage your global state

Thor Event Emitter Event emitter to manage your state. An event emitter that allows you to manage your global state. Instead of using global giant obj

Apr 18, 2022

Global Game Jam Protopotes - Team Distanciel

Global Game Jam Protopotes - Team Distanciel

SCHRODINGER'S ESCAPE - 2022 Global Game Jam project Game resume Pr. Erwin Schrödinger really did his cat's experiment ! But, the cat found the craft b

Dec 14, 2022

Awesome TV is the First and Original streaming entertainment network for Global Africa from United States of America (USA).

Awesome TV is the First and Original streaming entertainment network for Global Africa from United States of America (USA).

LEADBOARD APP Awesome TV is the First and Original streaming entertainment network for Global Africa from United States of America (USA). Built With H

Apr 4, 2022

This experimental library patches the global custom elements registry to allow re-defining or reload a custom element.

Redefine Custom Elements This experimental library patches the global custom elements registry to allow re-defining a custom element. Based on the spe

Dec 11, 2022

An unreliable and overall unusable sorting library for numbers with a global cache on the edge.

unsort An unreliable and overall unusable sorting library for numbers with a global cache on the edge. the algorithm This library implements a number

May 19, 2022
Comments
  • windows下编译失效

    windows下编译失效

    //windows下的斜杠和linux下不一样
          if (
            fullPath.includes('antd/es/style/core/global') ||
            fullPath.includes('antd/lib/style/core/global') ||
            fullPath.includes('antd\\es\\style\\core\\global') ||
            fullPath.includes('antd\\lib\\style\\core\\global')
          ) {
            return true
          }
    
    opened by roytan883 5
Owner
null
A Masked Input Component based on Ant Design.

antd-input-mask A Masked Input Component based on Ant Design. Usage Example Contributing How to run PR template Issue template Developed by bem-te-vi

bem.te.vi 6 Oct 24, 2022
Demodal is a browser extension that automatically removes content blocking modals including paywalls, discount offers, promts to sign up or enter your email address and more.

Demodal Demodal is a browser extension that automatically removes content blocking modals including paywalls, discount offers, promts to sign up or en

Elbert Alias 225 Jan 4, 2023
A cache that automatically removes the least-recently-used items

A cache that automatically removes the least-recently-used items

Evandro Leopoldino Gonçalves 9 Feb 27, 2022
A simple single page web-app that stores, removes and edits books' names in the browser's local storage.

A simple single page web-app that stores, removes and edits books' names in the browser's local storage. Made with Webpack bundler

Alejandro Neira 5 Apr 1, 2022
A simplified list crud that adds, removes and edits items

To-do list This project is as simplified todo list crud. Built With HTML CSS JavaScript Webpack Live version See live version Getting Started To get a

Fernando Saldaña 7 Apr 2, 2022
Tiny JavaScript library (1kB) by CurrencyRate.today, providing simple way and advanced number, money and currency formatting and removes all formatting/cruft and returns the raw float value.

Zero dependency tiny JavaScript library (1kB bytes) by CurrencyRate.today, providing simple way and advanced number, money and currency formatting and removes all formatting/cruft and returns the raw float value.

Yurii De 11 Nov 8, 2022
🐜 GPU-accelerated ant colony simulation

Ants simulation A simple ant colony GPU-accelerated simulation made with Three.js. Live demo Rules Ants can emit two types of pheromones: to-home pher

null 10 Nov 28, 2022
An esbuild plugin for simplifying global API calls.

esbuild-plugin-global-api This plugin is still experimental, not recommended for production. It may break your code in some cases. An esbuild plugin f

null 4 Nov 15, 2022
A PostCSS plugin that transforms `css var` to `less var`.

PostCSS CSS var to Less var A PostCSS plugin to convert CSS variables to Less variables Installation npm install postcss-transform-css-var Examples /

cherry-man 9 Nov 28, 2022
A custom Chakra UI component that adds ready-made styles for rendering remote HTML content.

Chakra UI Prose Prose is a Chakra UI component that adds a ready-made typography styles when rendering remote HTML. Installation yarn add @nikolovlaza

Lazar Nikolov 50 Jan 3, 2023