@douyinfe/semi-webpack-plugin

中文文档
2.105.0发布于 2026/11/12MITCommonJS近 30 天下载 4494

A webpack plugin for Semi Design to custom theme、replace prefix and so on.

原始使用文档
文档目录7 节
  1. Introduction
  2. Usage
  3. Install
  4. Custom theme
  5. Replace prefix of CSS selector
  6. Api
  7. new SemiPlugin(options)

A webpack plugin for Semi Design to custom theme、replace prefix and so on.

Introduction

The plugin is designed for Semi Design, support webpack4 and webpack5, provides two major abilities:

  • Custom theme
  • Replace prefix of CSS selector

Note: The plugin detects Semi related dependencies by package path. It supports both @douyinfe/semi-ui and version-suffixed packages like @douyinfe/semi-ui-19 (also for semi-icons).

Usage

Install

Install @douyinfe/semi-webpack-plugin as a development dependency:

npm install --save-dev @douyinfe/semi-webpack-plugin
# or
yarn add --dev @douyinfe/semi-webpack-plugin

Custom theme

Semi Design uses the Scss variables to extract thousands of Design Tokens. You can replace Token through this plugin to achieve theme customization. More info

You can custom theme through three ways:

  • npm package for custom theme
  • Local Scss file in your project
  • Pass key-value pair parameters to plugin Priority from low to high.

Through npm package

In order to use the npm package, you need to customize the theme through Semi Design System.After finishing the customization, Semi DSM will generate a npm package for you, and then you can use it like this.

// webpack.config.js
const SemiPlugin = require('@douyinfe/semi-webpack-plugin').default;

module.exports = {
    // ...
    plugins: [
        new SemiPlugin({
            theme: '@douyinfe/semi-theme-default'
        })
    ]
    // ...
};

Through local Scss file

You can check which tokens can be customized on the Semi WebSite.

  • step1: add a local file
// local.scss
$font-size-small: 16px;

  • step2: config webpack
// webpack.config.js
const path = require('path');
const SemiPlugin = require('@douyinfe/semi-webpack-plugin').default;

module.exports = {
    // ...
    plugins: [
        new SemiPlugin({
            include: path.join(__dirname, 'local.scss')
        })
    ]
};

Through parameters

// webpack.config.js
const SemiPlugin = require('@douyinfe/semi-webpack-plugin').default;

module.exports = {
    // ...
    plugins: [
        new SemiPlugin({
            variables: {
                "$font-size-small": '16px'
            }
        })
    ]
};

Replace prefix of CSS selector

The CSS selectors used by Semi Design is prefixed with semi by default(e.g, .semi-button).You can replace the prefix through this plugin.

// webpack.config.js
const SemiPlugin = require('@douyinfe/semi-webpack-plugin').default;

module.exports = {
    // ...
    plugins: [
        new SemiPlugin({
            prefixCls: 'custom'
        })
    ]
    // ...
};

Then you get the replaced CSS selectors(e.g, .custom-button).

Api

new SemiPlugin(options)

options.prefixCls

Type: String

The prefix of CSS selector.

options.theme

Type: String or Object

When the type is string, it represents the name of npm for custom theme.You can use Semi Design System to custom theme.

options.theme.name

Same performance as when the type of options.theme is string.

options.include

Type: String

The absolute path of the local Scss file.

options.variables

Type: Object

The key-value pair of Scss token.

options.omitCss

Type: Boolean

In the compilation phase, whether to exclude css references.Used to solve the problem that Next.js does not support the global introduction of css in third-party code.See this discussion.

options.webpackContext.NormalModule

Type: webpack NormalModule

options.extractCssOptions.loader

Type: String

The path of webpack loader that extract css.

options.extractCssOptions.loaderOptions

Type: Object

The options of webpack loader that extract css.

options.overrideStylesheetLoaders

Type: (loaderList:any[])=>any[]

You can customize how webpack process semi related styles by override the loader with this option. The function will receive the loader list of default loaders(include options.extractCssOptions) and you should return your new loader list. The best practice is just only add your loader to the list rather than delete or change the default loaders since some core logic is in there.

In webpack@5, some hooks need to be obtained through api NormalModule.getCompilationHooks. But in some scenarios, webpack will not be installed, such as Next.js. Therefore, the user is required to pass in NormalModule as a parameter.

版本与发布记录

@douyinfe/semi-webpack-plugin 共发布 590 个版本,首次发布于 2021/10/25;过去 12 个月发布了 67 个版本。

版本发布日期距今
2.105.0latest2026/11/121 天前
2.104.02026/10/091 个月前
2.103.02026/09/012 个月前
2.102.02026/07/313 个月前
2.38.4-alpha.2-3117-31202026/07/293 个月前
2.101.12026/07/203 个月前

其他发布通道:test → 2.38.3-alpha.4,patch-table → 2.38.3-alpha.2-patch-table,patch-tooltip → 2.70.1-alpha.1-patch-tooltip,2.58.0-hotfix-aria → 2.58.0-hotfix-aria,2.55.5-hotfix-aria → 2.55.5-hotfix-aria,hotfix → 2.38.3-alpha.2-patch-2254。

关于 @douyinfe/semi-webpack-plugin 的常见问题

@douyinfe/semi-webpack-plugin 是什么?

A webpack plugin for Semi Design to custom theme、replace prefix and so on.

如何安装 @douyinfe/semi-webpack-plugin?

在项目目录运行 npm install @douyinfe/semi-webpack-plugin,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:webpack(^5.77.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@douyinfe/semi-webpack-plugin 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/douyinfe__semi-webpack-plugin 是否存在。

@douyinfe/semi-webpack-plugin 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@douyinfe/semi-webpack-plugin 可以商用吗?

@douyinfe/semi-webpack-plugin 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@douyinfe/semi-webpack-plugin 的下载量有多少?

根据 npm 官方下载统计,@douyinfe/semi-webpack-plugin 在 2026/10/13 – 2026/11/11 这 30 天内被下载 4,494 次,日均约 150 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@douyinfe/semi-webpack-plugin 还在维护吗?

最新版本 2.105.0 发布于 2026/11/12(1 天前);至今共发布 590 个版本,其中过去 12 个月发布了 67 个;首次发布于 2021/10/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。