Browse Source

fixed vite theme plugin

pull/710/head
cKey 3 years ago
parent
commit
9c0cd0ab05
  1. 17
      apps/vue/build/vite/plugin/theme.ts

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

@ -20,8 +20,8 @@ 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) {
@ -44,7 +44,18 @@ export function configThemePlugin(isBuild: boolean): PluginOption[] {
return s.startsWith('[data-theme') ? s : `[data-theme] ${s}`; return s.startsWith('[data-theme') ? s : `[data-theme] ${s}`;
}, },
colorVariables: [...getThemeColors(), ...colors], colorVariables: [...getThemeColors(), ...colors],
}), });
vite_theme_plugin.forEach(function (item) {
//对vite:theme插件特殊配置
if ('vite:theme' === item.name) {
// 打包时去除enforce: "post",vite 2.6.x适配,否则生成app-theme-style为空,因为async transform(code, id) {的code没有正确获取
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