Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Fixed variable undefined after vite upgrade version 3;Fixed Production mode switching theme failure. #30

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface ViteThemeOptions {
fileName?: string;
injectTo?: InjectTo;
verbose?: boolean;
isProd: boolean; // 必须传递环境标识
}

import { createFileHash, formatCss } from './utils';
Expand Down Expand Up @@ -49,6 +50,7 @@ export function viteThemePlugin(opt: ViteThemeOptions): Plugin[] {
fileName: 'app-theme-style',
injectTo: 'body',
verbose: true,
isProd: true, // 默认为 true,切换主题只在生产环境生效。
},
opt
);
Expand Down Expand Up @@ -81,7 +83,7 @@ export function viteThemePlugin(opt: ViteThemeOptions): Plugin[] {
}),
{
...emptyPlugin,
enforce: 'post',
enforce: options.isProd ? undefined : 'post', // 生产环境不设置 enforce;开发环境设置为 post,切换主题才会都生效。
configResolved(resolvedConfig) {
config = resolvedConfig;
isServer = resolvedConfig.command === 'serve';
Expand Down
2 changes: 1 addition & 1 deletion src/injectClientPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function injectClientPlugin(

if (
nid === CLIENT_PUBLIC_ABSOLUTE_PATH ||
nid.endsWith(path) ||
nid.includes(path) ||
// support .vite cache
nid.includes(path.replace(/\//gi, '_'))
) {
Expand Down