> A rspack plugin for Semi Design to custom theme、replace prefix and so on.
npm install @douyinfe/semi-rspack-plugin> A rspack plugin for Semi Design to custom theme、replace prefix and so on.
> 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).
@douyinfe/semi-rspack-plugin as a development dependency:`` shell`
npm install --save-dev @douyinfe/semi-rspack-pluginor
yarn add --dev @douyinfe/semi-rspack-plugin
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.
` js
// rspack.config.js
const {SemiRspackPlugin} = require('@douyinfe/semi-rspack-plugin');
module.exports = {
// ...
plugins: [
new SemiRspackPlugin({
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
` scss
// local.scss
$font-size-small: 16px;
``
- step2: config rspack js
// rspack.config.js
const path = require('path');
const {SemiRspackPlugin} = require('@douyinfe/semi-rspack-plugin');
module.exports = {
// ...
plugins: [
new SemiRspackPlugin({
include: path.join(__dirname, 'local.scss')
})
]
};
`
#### Through parameters
` js
// rspack.config.js
const {SemiRspackPlugin} = require('@douyinfe/semi-rspack-plugin');
module.exports = {
// ...
plugins: [
new SemiRspackPlugin({
variables: {
"$font-size-small": '16px'
}
})
]
};
`
).You can replace the prefix through this plugin.` js
// rspack.config.js
const {SemiRspackPlugin} = require('@douyinfe/semi-rspack-plugin');module.exports = {
// ...
plugins: [
new SemiRspackPlugin({
prefixCls: 'custom'
})
]
// ...
};
`Then you get the replaced CSS selectors(e.g,
.custom-button).Api
$3
#### options.prefixCls
Type:
StringThe prefix of CSS selector.
#### options.theme
Type:
String or ObjectWhen 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:
StringThe absolute path of the local Scss file.
##### options.variables
Type:
ObjectThe key-value pair of Scss token.
##### options.omitCss
Type:
BooleanIn 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.extractCssOptions.loader
Type:
StringThe path of webpack/rspack loader that extract css.
##### options.extractCssOptions.loaderOptions
Type:
ObjectThe options of webpack/rspack 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.