소스 검색

fix: re-add base to vite.config.js with debug log

Vite's base option controls both @vite/client injection AND JS module import
path resolution. Without it, all import specifiers resolve from origin root
instead of /ads-preview/ prefix. Added console.log to verify config loading.
guoziyun 3 주 전
부모
커밋
25577e68c8
1개의 변경된 파일6개의 추가작업 그리고 0개의 파일을 삭제
  1. 6 0
      templates/coloring/vite.config.js

+ 6 - 0
templates/coloring/vite.config.js

@@ -42,7 +42,13 @@ module.exports = defineConfig(({ mode }) => {
   const output = platformBuild?.output;
   const outDir = output ? `dist/${output}` : "dist";
 
+  // 预览模式下通过 PREVIEW_BASE_PATH 设置 base,如 /ads-preview/
+  // 这会控制 Vite 注入的 @vite/client 路径 + 所有 JS import 模块路径的前缀
+  const base = process.env.PREVIEW_BASE_PATH || undefined;
+  if (base) console.log(`[vite:config] base = ${base}`);
+
   return {
+    base,
     plugins: [viteSingleFile(), finalizeHtmlPlugin(outDir, adapter)],
     server: {
       allowedHosts: ["color2.jccytech.cn", "localhost", ".jccytech.cn"],