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

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

View File

@@ -5,16 +5,20 @@ 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 = {
function getDevHttpsConfig() {
return {
key: fs.readFileSync(path.join(rootDir, "certs/localhost+2-key.pem")), key: fs.readFileSync(path.join(rootDir, "certs/localhost+2-key.pem")),
cert: fs.readFileSync(path.join(rootDir, "certs/localhost+2.pem")) cert: fs.readFileSync(path.join(rootDir, "certs/localhost+2.pem"))
}; };
}
export default defineConfig({ export default defineConfig(({ command }) => ({
server: { server: command === "serve"
? {
port: 5174, port: 5174,
strictPort: true, strictPort: true,
https: httpsConfig, https: getDevHttpsConfig(),
headers: { headers: {
// 关键:添加 COEP 和 COOP // 关键:添加 COEP 和 COOP
"Cross-Origin-Embedder-Policy": "credentialless", // 或 "require-corp" "Cross-Origin-Embedder-Policy": "credentialless", // 或 "require-corp"
@@ -31,4 +35,5 @@ export default defineConfig({
"/storage": "http://127.0.0.1:3001" "/storage": "http://127.0.0.1:3001"
} }
} }
}); : undefined
}));