|
@@ -53,19 +53,19 @@ async function startPreview(creativeId, theme, storageDir) {
|
|
|
const configContent = (0, configGenerator_1.generateAdConfig)({ creativeId, theme, storageDir });
|
|
const configContent = (0, configGenerator_1.generateAdConfig)({ creativeId, theme, storageDir });
|
|
|
const configPath = path_1.default.join(TEMPLATE_DIR, "src", "filler", "_ad_config_.ts");
|
|
const configPath = path_1.default.join(TEMPLATE_DIR, "src", "filler", "_ad_config_.ts");
|
|
|
fs_1.default.writeFileSync(configPath, configContent, "utf-8");
|
|
fs_1.default.writeFileSync(configPath, configContent, "utf-8");
|
|
|
- // 4. 通过 VITE_BASE 环境变量传入 base 路径(vite.config.js 读取)
|
|
|
|
|
|
|
+ // 4. 通过 --base CLI 参数传入 base 路径,确保 Vite dev server 和 HTML 注入都使用正确前缀
|
|
|
// 注意:nginx 必须配合去掉 proxy_pass 尾部斜杠,保持 /ads-preview/ 前缀不变
|
|
// 注意:nginx 必须配合去掉 proxy_pass 尾部斜杠,保持 /ads-preview/ 前缀不变
|
|
|
const previewBase = process.env.PREVIEW_BASE_PATH || "/";
|
|
const previewBase = process.env.PREVIEW_BASE_PATH || "/";
|
|
|
console.log(`[preview] Starting Vite dev server on port ${PREVIEW_PORT} (base: ${previewBase})...`);
|
|
console.log(`[preview] Starting Vite dev server on port ${PREVIEW_PORT} (base: ${previewBase})...`);
|
|
|
viteProcess = (0, child_process_1.spawn)(path_1.default.join(TEMPLATE_DIR, "node_modules", ".bin", "vite"), [
|
|
viteProcess = (0, child_process_1.spawn)(path_1.default.join(TEMPLATE_DIR, "node_modules", ".bin", "vite"), [
|
|
|
"--port", String(PREVIEW_PORT),
|
|
"--port", String(PREVIEW_PORT),
|
|
|
"--strictPort",
|
|
"--strictPort",
|
|
|
|
|
+ "--base", previewBase,
|
|
|
], {
|
|
], {
|
|
|
cwd: TEMPLATE_DIR,
|
|
cwd: TEMPLATE_DIR,
|
|
|
env: {
|
|
env: {
|
|
|
...process.env,
|
|
...process.env,
|
|
|
AD_CONFIG_PATH: "src/filler/_ad_config_.ts",
|
|
AD_CONFIG_PATH: "src/filler/_ad_config_.ts",
|
|
|
- VITE_BASE: previewBase,
|
|
|
|
|
},
|
|
},
|
|
|
stdio: ["ignore", "pipe", "pipe"],
|
|
stdio: ["ignore", "pipe", "pipe"],
|
|
|
});
|
|
});
|