perf: 공개 첫 화면에서 MOCK·Studio 코드를 빼고 초기 JS 예산을 측정값으로 정한다 #9

Merged
donghyeon.kang merged 5 commits from perf/initial-js-budget into main 2026-11-12 21:51:04 +00:00
2 changed files with 47 additions and 0 deletions
Showing only changes of commit 0bb8f1df9c - Show all commits
@@ -0,0 +1,32 @@
import { readdirSync, readFileSync } from "node:fs";
import path from "node:path";
import { describe, expect, it } from "vitest";
const DESIGN_SYSTEM = "src/presentation/design-system";
function sourceFiles(directory: string): string[] {
return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
const file = path.posix.join(directory, entry.name);
if (entry.isDirectory()) return sourceFiles(file);
return /\.tsx?$/u.test(entry.name) && !/\.stories\.tsx?$/u.test(entry.name)
? [file]
: [];
});
}
/**
* vite.config.ts 가 design-system 모듈을 side effect 없음으로 선언한다(템플릿 1101/08-08).
* 그 아래에서는 `import "x"` 처럼 효과만을 위한 import 가 모듈과 같이 빌드에서 사라진다.
* 그런 import 가 생기면 선언이 틀린 것이다.
*/
describe("design-system modules declared free of side effects", () => {
it("hold no import kept only for its effect", () => {
const files = sourceFiles(DESIGN_SYSTEM);
expect(files.length).toBeGreaterThan(0);
const effectOnly = files.filter((file) =>
/^\s*import\s+["'][^"']+["']/mu.test(readFileSync(file, "utf8")),
);
expect(effectOnly).toEqual([]);
});
});
+15
View File
@@ -138,6 +138,21 @@ export default defineConfig(({ mode }) => {
// Template sync (af3d8e6): the template's chunk groups, then TechLog's
// named route chunks, in the template's `codeSplitting` form.
rolldownOptions: {
/*
템플릿 1101/08-08(51941a54)과 같다. design-system 모듈은 컴포넌트·아이콘·토큰 목록을
선언만 하고 top-level 효과가 없다. 그렇게 선언해 두면 공개 셸이 배럴(index.ts)에서
Button 하나를 가져와도, 아무 export 도 안 쓰인 primitive 파일은 초기 청크에서
빠진다. 효과만을 위한 import 를 두면 선언 아래에서 모듈과 같이 사라지므로 이 범위에는
그런 import 가 없다. CSS 는 bootstrap/main.tsx 에서 읽는다.
*/
treeshake: {
moduleSideEffects: [
{
test: /[\\/]src[\\/]presentation[\\/]design-system[\\/].+\.tsx?$/,
sideEffects: false,
},
],
},
output: {
codeSplitting: {
groups: [