-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
61 lines (54 loc) · 1.61 KB
/
Copy pathvite.config.js
File metadata and controls
61 lines (54 loc) · 1.61 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
import { defineConfig } from "vite";
import { utimes } from "node:fs/promises";
import { resolve, dirname } from "node:path";
import { fileURLToPath } from "node:url";
const here = dirname(fileURLToPath(import.meta.url));
const assetRoot = resolve(here, "resources/assets");
export default defineConfig({
root: here,
base: "",
plugins: [
{
name: "refresh-directory-publication-key",
apply: "build",
async closeBundle(error) {
if (error) {
return;
}
// Yii2 keys published directories by their root mtime, while Vite only
// rewrites nested dist files. Refresh the root after a successful build.
var now = new Date();
await utimes(assetRoot, now, now);
},
},
],
build: {
outDir: "resources/assets/dist",
emptyOutDir: true,
cssCodeSplit: true,
target: "es2022",
minify: "oxc",
rolldownOptions: {
input: {
debug: resolve(here, "resources/src/core/debug.js"),
toolbar: resolve(here, "resources/src/toolbar/index.js"),
},
output: {
entryFileNames: "js/[name].min.js",
chunkFileNames: "js/[name].min.js",
assetFileNames: (info) => {
const name = info.names?.[0] ?? info.name ?? "";
if (name.endsWith(".css")) {
const base = name.replace(/^css-/, "").replace(/\.css$/, "");
return `css/${base}.min.css`;
}
if (/\.(woff2?|ttf)$/.test(name)) {
return "fonts/[name][extname]";
}
return "[ext]/[name].[ext]";
},
manualChunks: undefined,
},
},
},
});