feat: 完成模板预览隔离与矩阵验收
This commit is contained in:
1 parent
d38dbe02aa
commit
5bf54096be
13 files changed
+287
-19
No files matched your search
@@ -2,10 +2,40 @@ import { defineConfig } from "vite";
|
||||
import react from "@vitejs/plugin-react";
|
||||
import { templatePreviewCss } from "./template-preview-css.mjs";
|
||||
|
||||
const adminCsp = [
|
||||
"default-src 'self'",
|
||||
"img-src 'self' data: blob:",
|
||||
"media-src 'self' data: blob:",
|
||||
"style-src 'self' 'unsafe-inline'",
|
||||
"font-src 'self' data:",
|
||||
"connect-src 'self' ws: wss:",
|
||||
"script-src 'self'",
|
||||
"object-src 'none'",
|
||||
"base-uri 'none'",
|
||||
"frame-ancestors 'self'",
|
||||
"form-action 'self'",
|
||||
].join("; ");
|
||||
const adminDevelopmentCsp = adminCsp.replace(
|
||||
"script-src 'self'",
|
||||
"script-src 'self' 'unsafe-inline'",
|
||||
);
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
plugins: [
|
||||
react(),
|
||||
{
|
||||
name: "admin-production-csp",
|
||||
// Vite dev preamble 是 inline script;生产构建保留 meta CSP,dev/preview 用响应头控制。
|
||||
transformIndexHtml(html, context) {
|
||||
const isDevelopmentServe =
|
||||
context.server?.config.command === "serve" && !context.server?.config.isProduction;
|
||||
return isDevelopmentServe
|
||||
? html.replace(/\s*<meta\s+http-equiv="Content-Security-Policy"[^>]*>/, "")
|
||||
: html;
|
||||
},
|
||||
},
|
||||
],
|
||||
css: { postcss: { plugins: [templatePreviewCss()] } },
|
||||
base: process.env.VITE_APP_BASE_PATH ?? "/",
|
||||
resolve: {
|
||||
dedupe: ["react", "react-dom"],
|
||||
alias: {
|
||||
@@ -23,6 +53,13 @@ export default defineConfig({
|
||||
server: {
|
||||
host: "0.0.0.0",
|
||||
port: Number(process.env.ADMIN_PORT ?? 3000),
|
||||
// Vite dev preamble 需要 inline script;preview/生产保留严格 CSP。
|
||||
headers: {
|
||||
"Content-Security-Policy": adminDevelopmentCsp,
|
||||
"Referrer-Policy": "no-referrer",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
},
|
||||
base: process.env.VITE_APP_BASE_PATH ?? "/",
|
||||
proxy: {
|
||||
"/api": {
|
||||
target: process.env.VITE_DEV_API_TARGET ?? "http://localhost:3001",
|
||||
@@ -43,6 +80,15 @@ export default defineConfig({
|
||||
: {}),
|
||||
},
|
||||
},
|
||||
preview: {
|
||||
// 响应头在 dev/preview 均生效;meta CSP 是静态托管环境的基础防线。
|
||||
headers: {
|
||||
"Content-Security-Policy": adminCsp,
|
||||
"Referrer-Policy": "no-referrer",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
},
|
||||
base: process.env.VITE_APP_BASE_PATH ?? "/",
|
||||
},
|
||||
build: {
|
||||
outDir: "dist",
|
||||
rollupOptions: {
|
||||
|
||||
Reference in new issue
Block a user