-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
52 lines (47 loc) · 1.42 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
// vite.config.js
import { defineConfig } from "vite";
import { splitVendorChunkPlugin } from 'vite'
import { glob } from "glob";
import path from "node:path";
import { fileURLToPath } from "node:url";
import fs from "node:fs";
// Create object for every endpoint for Rollup
const entryPoints = Object.fromEntries(
glob.sync("src/**/*.html").map((file) => [
// This remove `src/` as well as the file extension from each
// file, so e.g. src/nested/foo.js becomes nested/foo
path.relative(
"src",
file.slice(0, file.length - path.extname(file).length),
),
// This expands the relative paths to absolute paths, so e.g.
// src/nested/foo becomes /project/src/nested/foo.js
fileURLToPath(new URL(file, import.meta.url)),
]),
);
// Build array of posts for index page automation
const postArray = glob
.sync("src/**/*.json", { ignore: "src/public/postData.json" })
.map((file) => JSON.parse(fs.readFileSync(file, "utf8")));
// Sort by date, requires everything to have a date
const sortedPosts = [...postArray].sort(function(a,b){
return new Date(b.date) - new Date(a.date);
});
// Write posts to JSON
fs.writeFile(
"src/public/postData.json",
JSON.stringify(sortedPosts),
"utf8",
() => {},
);
export default defineConfig({
root: "src",
base: "/experiments/",
build: {
outDir: "../dist/",
rollupOptions: {
input: entryPoints,
},
},
plugins: [splitVendorChunkPlugin()],
});