mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-08-26 00:00:00 +08:00
* fix: 优化类型提示 * fix: 添加 enums 接口类型声明 * feat: 配置插件api提示 Co-authored-by: wanchun <445436867@qq.com>
74 lines
2.0 KiB
JavaScript
74 lines
2.0 KiB
JavaScript
import WindiCSS from 'vite-plugin-windicss';
|
|
import { name } from '../package.json';
|
|
|
|
function getWindicssConfig(api) {
|
|
const { config, ...otherOption } = api.config.windicss;
|
|
return {
|
|
config: {
|
|
extract: {
|
|
// A common use case is scanning files from the root directory
|
|
include: ['**/*.{vue,jsx,js,ts,tsx}'],
|
|
// if you are excluding files, make sure you always include node_modules and .git
|
|
exclude: ['node_modules', '.git', 'dist', '.fes'],
|
|
},
|
|
...config,
|
|
},
|
|
...otherOption,
|
|
};
|
|
}
|
|
|
|
function buildWindicssWithWebpack(api) {
|
|
api.chainWebpack((memo, { createCSSRule }) => {
|
|
memo.plugin('windicss').use(require('windicss-webpack-plugin'), [getWindicssConfig(api)]);
|
|
if (api.env === 'development') {
|
|
memo.module.rule('css').test((path) => {
|
|
if (path.endsWith('windi-utilities.css')) {
|
|
return false;
|
|
}
|
|
return /\.css$/.test(path);
|
|
});
|
|
createCSSRule({
|
|
lang: 'windicss',
|
|
test: /windi-utilities.css$/,
|
|
styleLoaderOption: {
|
|
insert: 'body',
|
|
},
|
|
});
|
|
}
|
|
|
|
return memo;
|
|
});
|
|
}
|
|
|
|
function buildWindicssWithVite(api) {
|
|
api.modifyBundleConfig((memo) => {
|
|
memo.plugins.push(WindiCSS(getWindicssConfig(api).config));
|
|
|
|
return memo;
|
|
});
|
|
}
|
|
|
|
export default (api) => {
|
|
api.describe({
|
|
key: 'windicss',
|
|
config: {
|
|
schema(joi) {
|
|
return joi.object();
|
|
},
|
|
default: {},
|
|
},
|
|
});
|
|
|
|
api.addEntryImportsAhead(() => [{ source: 'windi-base.css' }, { source: 'windi-components.css' }, { source: 'windi-utilities.css' }]);
|
|
|
|
if (api.builder.name === 'vite') {
|
|
buildWindicssWithVite(api);
|
|
} else {
|
|
buildWindicssWithWebpack(api);
|
|
}
|
|
|
|
api.addConfigType(() => ({
|
|
source: name,
|
|
}));
|
|
};
|