生产构建跳过本地开发证书

This commit is contained in:
zhangshun
2026-06-02 11:46:55 +08:00
parent e215f93ef2
commit 8fb45bd42a

View File

@@ -5,30 +5,35 @@ import { fileURLToPath } from "node:url";
const __dirname = path.dirname(fileURLToPath(import.meta.url)); const __dirname = path.dirname(fileURLToPath(import.meta.url));
const rootDir = path.resolve(__dirname, "../.."); const rootDir = path.resolve(__dirname, "../..");
const httpsConfig = {
key: fs.readFileSync(path.join(rootDir, "certs/localhost+2-key.pem")),
cert: fs.readFileSync(path.join(rootDir, "certs/localhost+2.pem"))
};
export default defineConfig({ function getDevHttpsConfig() {
server: { return {
port: 5174, key: fs.readFileSync(path.join(rootDir, "certs/localhost+2-key.pem")),
strictPort: true, cert: fs.readFileSync(path.join(rootDir, "certs/localhost+2.pem"))
https: httpsConfig, };
headers: { }
// 关键:添加 COEP 和 COOP
"Cross-Origin-Embedder-Policy": "credentialless", // 或 "require-corp" export default defineConfig(({ command }) => ({
"Cross-Origin-Opener-Policy": "same-origin", server: command === "serve"
"Cross-Origin-Resource-Policy": "cross-origin", // 改为 cross-origin ? {
// 开发环境允许跨域 port: 5174,
"Access-Control-Allow-Origin": "https://localhost:3000", // 父页面的地址 strictPort: true,
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", https: getDevHttpsConfig(),
"Access-Control-Allow-Headers": "Content-Type", headers: {
"Access-Control-Allow-Credentials": "true" // 关键:添加 COEP 和 COOP
}, "Cross-Origin-Embedder-Policy": "credentialless", // 或 "require-corp"
proxy: { "Cross-Origin-Opener-Policy": "same-origin",
"/api": "http://127.0.0.1:3001", "Cross-Origin-Resource-Policy": "cross-origin", // 改为 cross-origin
"/storage": "http://127.0.0.1:3001" // 开发环境允许跨域
"Access-Control-Allow-Origin": "https://localhost:3000", // 父页面的地址
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Allow-Credentials": "true"
},
proxy: {
"/api": "http://127.0.0.1:3001",
"/storage": "http://127.0.0.1:3001"
}
} }
} : undefined
}); }));