-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.js
More file actions
79 lines (74 loc) · 2.56 KB
/
Copy pathvite.config.js
File metadata and controls
79 lines (74 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { createHash } from "crypto";
function pad2(value) {
return String(value).padStart(2, "0");
}
// 빌드 머신(예: GitHub Actions 러너는 UTC)과 무관하게 한국시간(KST, GMT+9) 벽시계로 고정한다.
// UTC 인스턴트에 +9시간을 더한 뒤 getUTC*로 읽으면 타임존 설정에 의존하지 않는다. KST는 서머타임이 없어 항상 +9.
const now = new Date();
const kst = new Date(now.getTime() + 9 * 60 * 60 * 1000);
const buildDate = `${kst.getUTCFullYear()}-${pad2(kst.getUTCMonth() + 1)}-${pad2(kst.getUTCDate())} ${pad2(kst.getUTCHours())}:${pad2(kst.getUTCMinutes())}`;
function shortChunkName(chunkInfo) {
const h = createHash("sha256").update(chunkInfo.name || "chunk").digest("hex").slice(0, 8);
return `assets/${h}.js`;
}
function shortenLongFilenames() {
const renames = new Map();
const short = (longName) => {
if (renames.has(longName)) return renames.get(longName);
const base = longName.replace(/^assets\//, "").replace(/\.[^.]+$/, "");
const ext = longName.includes(".css") ? ".css" : longName.match(/\.[^.]+$/)?.[0] || ".js";
const h = createHash("sha256").update(base).digest("hex").slice(0, 8);
const shortName = `assets/${h}${ext}`;
renames.set(longName, shortName);
return shortName;
};
return {
name: "shorten-long-filenames",
generateBundle(_, bundle) {
const entries = Object.entries(bundle);
for (const [fileName, output] of entries) {
if (fileName.length < 25) continue;
const newName = short(fileName);
if (newName === fileName) continue;
output.fileName = newName;
bundle[newName] = output;
delete bundle[fileName];
for (const item of Object.values(bundle)) {
if (item.type === "chunk" && item.code) {
item.code = item.code.split(fileName).join(newName);
}
if (item.type === "asset" && typeof item.source === "string") {
item.source = item.source.split(fileName).join(newName);
}
}
}
}
};
}
export default {
root: 'src',
publicDir: '../public',
define: {
__BUILD_DATE__: JSON.stringify(buildDate)
},
server: {
host: true,
port: 5173
},
build: {
outDir: '../dist',
emptyOutDir: true,
rollupOptions: {
input: {
main: 'src/index.html',
route: 'src/route.html'
},
output: {
chunkFileNames: shortChunkName,
entryFileNames: 'assets/[name]-[hash:8].js',
assetFileNames: 'assets/[name]-[hash:8][extname]'
},
plugins: [shortenLongFilenames()]
}
}
}