문제: 앱·Service Worker·선택 레시피 번들의 청크 설정이 Vite 8에서 @deprecated인 build.rollupOptions 별칭에 있었다(0929/13-07, 세 라운드 남음). 별칭이 지워지는 Vite 버전으로 올리면 청크 그룹과 treeshake 설정이 조용히 빠질 수 있다. 고른 방법: 세 곳의 키 이름만 rolldownOptions로 바꾼다. 내용은 그대로다. 위험·한계: 없음에 가깝다. 같은 설정의 정식 이름이다. 검증: 바꾸기 전후 빌드의 dist/assets 파일 이름이 모두 같다(해시가 같아 출력이 같다). service-worker-build-output 7건 통과, check:optional-recipes PASS(레시피 예산 4개 그대로). Refs: docs/reviews/2026-11-03-maturity-review/13-build-release-supply-chain.md 0929/13-07
108 lines
3.7 KiB
TypeScript
108 lines
3.7 KiB
TypeScript
import { readFile } from "node:fs/promises";
|
|
import { defineConfig } from "vite";
|
|
|
|
import { getBuildConfig } from "./src/contracts/env.ts";
|
|
import {
|
|
SERVICE_WORKER_CACHE_SCHEMA_VERSION,
|
|
SERVICE_WORKER_PROTOCOL_VERSION,
|
|
SERVICE_WORKER_SCRIPT_PATH,
|
|
} from "./src/contracts/service-worker.ts";
|
|
import { INSTALLED_RUNTIME_CAPABILITIES } from "./src/features/installed-runtime-capabilities.ts";
|
|
import { resolveServiceWorkerBuildInput } from "./scripts/lib/service-worker-build-input.ts";
|
|
|
|
/**
|
|
* §17.2.2 step 5. The Service Worker build.
|
|
*
|
|
* Runs only when the static selection is `ACTIVE`, after the app build has
|
|
* completed and the hashed asset list has been generated. `emptyOutDir` is
|
|
* false so it adds `service-worker.js` beside the already-built app rather than
|
|
* replacing it.
|
|
*/
|
|
|
|
const selection = INSTALLED_RUNTIME_CAPABILITIES.serviceWorker;
|
|
|
|
// Relative to this file: Vite's default `bundle` config loader runs the config
|
|
// from `node_modules/.vite-temp/`, so a bare `import("./.generated/...")` would
|
|
// resolve there. Every loader keeps `import.meta.url` pointing at this file.
|
|
async function readGenerated<T>(path: string, exportName: string): Promise<T> {
|
|
try {
|
|
const module = (await import(new URL(path, import.meta.url).href)) as Record<
|
|
string,
|
|
unknown
|
|
>;
|
|
if (!(exportName in module)) {
|
|
throw new TypeError(`Generated module does not export ${exportName}.`);
|
|
}
|
|
return module[exportName] as T;
|
|
} catch (error) {
|
|
throw new TypeError(`Required generated module is unavailable: ${path}`, {
|
|
cause: error,
|
|
});
|
|
}
|
|
}
|
|
|
|
const assets = await readGenerated(
|
|
"./.generated/frontend-runtime/service-worker-assets.ts",
|
|
"SERVICE_WORKER_ASSETS",
|
|
);
|
|
const contractSet = await readGenerated<{ setDigest?: string }>(
|
|
"./.generated/frontend-runtime/contract-set.ts",
|
|
"BUILD_CONTRACT_SET",
|
|
);
|
|
// 06-10 / F-8. The profile document `scripts/generate-runtime-config.ts` wrote
|
|
// in step 4, not `public/config.json`, which is always the local profile.
|
|
const runtimeConfig = JSON.parse(
|
|
await readFile("dist/config.json", "utf8"),
|
|
) as Record<string, string>;
|
|
|
|
const buildId = process.env.VITE_BUILD_ID ?? "local-build";
|
|
const releaseId = process.env.RELEASE_ID ?? "local-release";
|
|
const buildInput = resolveServiceWorkerBuildInput({
|
|
selection,
|
|
assets,
|
|
contractSet,
|
|
runtimeConfig,
|
|
appProfile: process.env.APP_PROFILE ?? "local",
|
|
buildId,
|
|
releaseId,
|
|
});
|
|
|
|
export default defineConfig({
|
|
// 0929/06-01. `dist` already holds the app build, `public/` included. Copying
|
|
// `public/` again would put the local `public/config.json` back over the
|
|
// profile document step 4 wrote.
|
|
publicDir: false,
|
|
build: {
|
|
// §17.2.2: exactly one input, exactly one output, no additional chunk.
|
|
emptyOutDir: false,
|
|
sourcemap: false,
|
|
rolldownOptions: {
|
|
input: "src/adapters/service-worker/service-worker-entry.ts",
|
|
output: {
|
|
format: "es",
|
|
inlineDynamicImports: true,
|
|
entryFileNames: SERVICE_WORKER_SCRIPT_PATH,
|
|
},
|
|
},
|
|
},
|
|
define: {
|
|
__CA_SERVICE_WORKER_BUILD_INFO__: JSON.stringify({
|
|
serviceWorkerProtocolVersion: SERVICE_WORKER_PROTOCOL_VERSION,
|
|
cacheSchemaVersion: SERVICE_WORKER_CACHE_SCHEMA_VERSION,
|
|
buildId,
|
|
releaseId,
|
|
contractSetDigest: buildInput.contractSetDigest,
|
|
staticAssetSetDigest: buildInput.assets.setDigest,
|
|
}),
|
|
__CA_SERVICE_WORKER_ASSETS__: JSON.stringify(buildInput.assets),
|
|
__CA_SERVICE_WORKER_HANDLERS__: JSON.stringify(buildInput.handlers),
|
|
// 0929/06-02. The page's own default, which follows the router base path.
|
|
__CA_RUNTIME_CONFIG_URL__: JSON.stringify(
|
|
getBuildConfig(process.env).runtimeConfigUrl,
|
|
),
|
|
__CA_RELEASE_MANIFEST_URL__: JSON.stringify(
|
|
buildInput.releaseManifestUrl,
|
|
),
|
|
},
|
|
});
|