Ant Design Build Plugin for legacy build-scripts
build-plugin-antd is a legacy plugin designed for older build-scripts based build systems, specifically to integrate Ant Design components. It provides functionalities for customizing Ant Design's Less variables via `modifyVars` and automatically applies `babel-plugin-import` for on-demand loading of Ant Design components, helping to reduce bundle size. The package is currently at version 0.1.4, indicating it is an early release. Its release cadence is effectively stalled, with no recent updates indicated. It appears to be superseded by `@ice/plugin-antd` in the modern Ice.js ecosystem, which is part of the `@ice/app` framework. As such, `build-plugin-antd` is likely abandoned or in a state of indefinite maintenance. Its primary differentiator was simplifying Ant Design integration within the specific `build-scripts` environment it targeted.
Common errors
-
Error: Plugin 'build-plugin-antd' not found.
cause The plugin package was not installed or is incorrectly referenced in the build configuration.fixRun `npm install build-plugin-antd` or `yarn add build-plugin-antd`. Ensure the plugin name is correctly spelled in your `build.config.js` or `ice.config.ts`. -
TypeError: antdPlugin is not a function
cause The plugin might be imported incorrectly (e.g., a named import for a default export) or the `require` statement returned something other than an executable function.fixIf using ESM, ensure `import antdPlugin from 'build-plugin-antd';` is used. If CommonJS, `const antdPlugin = require('build-plugin-antd');`. Verify the plugin is correctly invoked as a function in the `plugins` array, e.g., `antdPlugin()`. -
Less variable '@primary-color' not found.
cause Less `modifyVars` are not being applied correctly, or `javascriptEnabled` is not set for the Less loader, which Ant Design often requires for theme variables.fixCheck your build configuration's Less loader settings. Ensure `javascriptEnabled: true` is set for Less compilation and that `modifyVars` are correctly passed through to the Less processor, either directly or via the plugin's options.
Warnings
- breaking The `build-plugin-antd` package (version 0.1.4) is likely abandoned and superseded by `@ice/plugin-antd` in the modern Ice.js ecosystem. It is not actively maintained and may have compatibility issues with newer Node.js versions, build tools, or Ant Design releases.
- gotcha This plugin relies on `babel-plugin-import` for on-demand loading, which may not be compatible with all modern build tools (e.g., Vite, Rspack) or if your project primarily uses SWC/ESBuild for JavaScript transformations. Integration might require manual adjustments or an alternative approach.
- gotcha The Less `modifyVars` functionality might conflict or require specific configuration depending on how your project handles Less compilation. In particular, ensuring `javascriptEnabled: true` is correctly propagated to the Less loader is crucial for Ant Design themes.
- deprecated Given its low version number (0.1.4) and lack of recent updates, this plugin may not support the latest features or versions of Ant Design itself, potentially leading to compatibility issues with newer Ant Design components or APIs, or a less optimized build.
Install
-
npm install build-plugin-antd -
yarn add build-plugin-antd -
pnpm add build-plugin-antd
Imports
- antdPlugin
import { antdPlugin } from 'build-plugin-antd';import antdPlugin from 'build-plugin-antd';
- antdPlugin (CommonJS)
const { antdPlugin } = require('build-plugin-antd');const antdPlugin = require('build-plugin-antd'); - AntdPluginOptions (Type)
import { AntdPluginOptions } from 'build-plugin-antd';import type { AntdPluginOptions } from 'build-plugin-antd';
Quickstart
import { defineConfig } from '@ice/app'; // Or an equivalent build-scripts defineConfig utility
import antdPlugin from 'build-plugin-antd';
export default defineConfig(() => ({
// Other build configurations (e.g., output, assets, publicPath)
// ...
plugins: [
// Integrate build-plugin-antd with its configuration options
antdPlugin({
// Options for babel-plugin-import, applied to Ant Design components
libraryDirectory: 'es', // Specifies ES module path for tree-shaking
style: true, // Enables Less-based theme customization for Ant Design
// Additional babel-plugin-import options can be added here
}),
],
// Configuration for Less variables to customize Ant Design's theme
// This typically integrates with the underlying Less loader setup
less: {
modifyVars: {
'@primary-color': '#007bff', // Example: Change primary color to blue
'@link-color': '#007bff',
'@border-radius-base': '4px',
'@success-color': '#52c41a',
},
javascriptEnabled: true, // Required for Ant Design's Less theme variables
},
// ... additional build configurations for Ice.js or build-scripts
}));