Browse Source

Merge pull request #710 from colinin/fix-vite-theme-lugin

fixed vite theme plugin
pull/651/head
yx lin 3 years ago
committed by GitHub
parent
commit
e471c6d186
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 59
      apps/vue/build/vite/plugin/theme.ts

59
apps/vue/build/vite/plugin/theme.ts

@ -20,31 +20,42 @@ export function configThemePlugin(isBuild: boolean): PluginOption[] {
mixLighten, mixLighten,
tinycolor, tinycolor,
}); });
const plugin = [ // 抽取出viteThemePlugin插件,下方会根据不同环境设置enforce
viteThemePlugin({ const vite_theme_plugin = viteThemePlugin({
resolveSelector: (s) => { resolveSelector: (s) => {
s = s.trim(); s = s.trim();
switch (s) { switch (s) {
case '.ant-steps-item-process .ant-steps-item-icon > .ant-steps-icon': case '.ant-steps-item-process .ant-steps-item-icon > .ant-steps-icon':
return '.ant-steps-item-icon > .ant-steps-icon'; return '.ant-steps-item-icon > .ant-steps-icon';
case '.ant-radio-button-wrapper-checked:not(.ant-radio-button-wrapper-disabled)': case '.ant-radio-button-wrapper-checked:not(.ant-radio-button-wrapper-disabled)':
case '.ant-radio-button-wrapper-checked:not(.ant-radio-button-wrapper-disabled):hover': case '.ant-radio-button-wrapper-checked:not(.ant-radio-button-wrapper-disabled):hover':
case '.ant-radio-button-wrapper-checked:not(.ant-radio-button-wrapper-disabled):active': case '.ant-radio-button-wrapper-checked:not(.ant-radio-button-wrapper-disabled):active':
return s; return s;
case '.ant-steps-item-icon > .ant-steps-icon': case '.ant-steps-item-icon > .ant-steps-icon':
return s;
case '.ant-select-item-option-selected:not(.ant-select-item-option-disabled)':
return s;
default:
if (s.indexOf('.ant-btn') >= -1) {
// 按钮被重新定制过,需要过滤掉class防止覆盖
return s; return s;
case '.ant-select-item-option-selected:not(.ant-select-item-option-disabled)': }
return s; }
default: return s.startsWith('[data-theme') ? s : `[data-theme] ${s}`;
if (s.indexOf('.ant-btn') >= -1) { },
// 按钮被重新定制过,需要过滤掉class防止覆盖 colorVariables: [...getThemeColors(), ...colors],
return s; });
} vite_theme_plugin.forEach(function (item) {
} //对vite:theme插件特殊配置
return s.startsWith('[data-theme') ? s : `[data-theme] ${s}`; if ('vite:theme' === item.name) {
}, // 打包时去除enforce: "post",vite 2.6.x适配,否则生成app-theme-style为空,因为async transform(code, id) {的code没有正确获取
colorVariables: [...getThemeColors(), ...colors], if (isBuild) {
}), delete item.enforce;
}
}
});
const plugin = [
vite_theme_plugin,
antdDarkThemePlugin({ antdDarkThemePlugin({
preloadFiles: [ preloadFiles: [
path.resolve(process.cwd(), 'node_modules/ant-design-vue/dist/antd.less'), path.resolve(process.cwd(), 'node_modules/ant-design-vue/dist/antd.less'),

Loading…
Cancel
Save