-
Notifications
You must be signed in to change notification settings - Fork 19
/
vite.config.js
96 lines (93 loc) · 2.37 KB
/
vite.config.js
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { createVuePlugin } from "vite-plugin-vue2";
import { defineConfig } from "vite";
import { execSync } from "child_process";
import { promisify } from "util";
import {
readFile as readFileCallback,
writeFile as writeFileCallback,
} from "fs";
import { resolve } from "path";
const readFile = promisify(readFileCallback);
const writeFile = promisify(writeFileCallback);
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
createVuePlugin(),
(function myPlugin() {
return {
name: "service-worker-cache-file-list",
async closeBundle() {
await writeFile(
resolve(__dirname, "./dist/me/service-worker.js"),
(
await readFile(
resolve(__dirname, "./dist/me/service-worker.js"),
"utf-8",
)
).replace(
'["CACHE_URLS_PLACEHOLDER"]',
JSON.stringify(
await (
await import("globby")
).globby("./{assets,img}/**", {
cwd: resolve(__dirname, "./dist/me"),
}),
),
),
);
},
};
})(),
],
base: "/me/",
build: {
manifest: true,
outDir: resolve(__dirname, "./dist/me"),
rollupOptions: {
input: {
app: "./index.html",
"service-worker": "./src/service-worker/index.js",
},
output: {
entryFileNames: (assetInfo) => {
return assetInfo.name === "service-worker"
? "service-worker.js"
: "assets/js/[name]-[hash].js";
},
},
},
},
define: {
"process.env.VITE_BUILD_DATE": JSON.stringify(new Date().toISOString()),
"process.env.VITE_BUILD_COMMIT_HASH": JSON.stringify(
execSync("git log -1 --format=%H", {
encoding: "ascii",
}).trim(),
),
"process.env.VITE_BUILD_COMMIT_DATE": JSON.stringify(
new Date(
execSync("git log -1 --format=%ct", {
encoding: "ascii",
}).trim() * 1000,
).toISOString(),
),
},
resolve: {
alias: [
{
find: "@",
replacement: resolve(__dirname, "./src"),
},
{
find: "vue",
replacement: resolve(
__dirname,
"./node_modules/vue/dist/vue.runtime.esm.js",
),
},
],
},
server: {
host: "127.0.0.1",
},
});