ice.js plugin for using Fusion Design components with automatic style importing and theme customization
npx @tessl/cli install tessl/npm-ice--plugin-fusion@1.1.0@ice/plugin-fusion is an ice.js plugin that enables seamless integration of Alibaba Fusion Design components within ice.js applications. It provides automatic style importing capabilities for Fusion components, theme customization through SCSS variables, and multi-theme support through configurable theme packages.
npm install @ice/plugin-fusionimport fusion from '@ice/plugin-fusion';import { defineConfig } from '@ice/app';
import fusion from '@ice/plugin-fusion';
export default defineConfig(() => ({
plugins: [
fusion({
importStyle: true,
themePackage: '@alifd/theme-design-pro',
theme: {
'primary-color': '#1890ff',
'css-prefix': 'next-'
}
})
]
}));@ice/plugin-fusion integrates with the ice.js build system through several key mechanisms:
onGetConfig, createLogger, generator)@ice/style-import for automatic component style loadingCreates an ice.js plugin instance configured for Fusion Design component integration.
/**
* Creates an ice.js plugin for Fusion Design component integration
* @param options - Configuration options for the plugin
* @returns Plugin configuration object with name and setup function
*/
function fusion(options?: PluginOptions): {
name: string;
setup: (context: any) => void;
};
interface PluginOptions {
/** Theme configuration via SCSS variables */
theme?: Record<string, string>;
/** Fusion component theme package name */
themePackage?: string;
/** Controls automatic style importing - true, false, or 'sass' */
importStyle?: Boolean | string;
}Usage Examples:
// Basic style importing
fusion({ importStyle: true })
// SASS style importing with theme package
fusion({
importStyle: 'sass',
themePackage: '@alifd/theme-design-pro'
})
// Custom theme variables
fusion({
importStyle: 'sass',
theme: {
'primary-color': '#1890ff',
'secondary-color': '#52c41a',
'css-prefix': 'next-'
}
})
// Combined configuration
fusion({
importStyle: 'sass',
themePackage: '@alifd/theme-design-pro',
theme: {
'primary-color': '#1890ff'
}
})When importStyle is enabled, the plugin automatically integrates with @ice/style-import to load Fusion component styles.
Configuration:
importStyle: true - Loads CSS styles (style2 files)importStyle: 'sass' - Loads SASS styles (style files) - recommended for theme customizationimportStyle: false - Disables automatic style importingInternal Behavior:
@ice/style-import for @alifd/next library@alifd/next/es/${componentName.toLowerCase()}/style or style2The plugin provides comprehensive theme customization through SCSS variables and theme packages.
Theme Packages:
variables.scss, icons.scss)@alifd/theme-design-proCustom Theme Variables:
theme optionprimary-color, secondary-color, css-prefix$variable: value; statementsMulti-theme Support:
themePackage is configured as an array, enables multi-theme capabilityThe plugin modifies webpack configuration to support theme customization:
SASS Loader Configuration:
sass-loader options in webpack rulesadditionalData merging for existing loader configurationsContent Injection Order:
$css-prefix: 'next-' !default;@import 'themePackage/variables.scss';$variable: value;Cross-platform Compatibility:
formatPath functionThe plugin includes built-in validation and helpful warnings:
Configuration Warnings:
themePackage is used with importStyle: true instead of 'sass'File Resolution:
Example Warning:
[Plugin Fusion] WARN: themePackage is configured, please configurate importStyle as "sass",
ohterwise, themes defined by sass variables will not take effect.interface PluginOptions {
/**
* Theme configuration via SCSS variables
* Each key-value pair becomes: $key: value;
*/
theme?: Record<string, string>;
/**
* Fusion component theme package name
* Examples: '@alifd/theme-design-pro', '@alifd/theme-ice-blue'
*/
themePackage?: string;
/**
* Controls automatic style importing
* - true: Import CSS styles (style2)
* - 'sass': Import SASS styles (style) - recommended for theming
* - false: Disable automatic importing
*/
importStyle?: Boolean | string;
}