-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvite.config.js
More file actions
56 lines (47 loc) · 1.48 KB
/
vite.config.js
File metadata and controls
56 lines (47 loc) · 1.48 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
import { injectHtml } from 'vite-plugin-html';
import glob from 'glob';
import path from 'path';
import drnm from 'drnm';
const basedir = drnm(import.meta.url)
export default function ({ mode }) {
let input = {};
const isProduction = mode === 'production';
// For production we need to specify all our entry points
// See https://vitejs.dev/guide/build.html#multi-page-app
if (isProduction) {
input.main = path.resolve(basedir, 'index.html');
const pages = glob.sync('pages/*.html', { absolute: true });
for (const page of pages) {
const fileName = path.parse(page).name;
input[fileName] = page;
}
}
return {
// base: isProduction ? '/css/' : '',
plugins: [
injectHtml({
injectOptions: { views: ['pages/includes'] },
}),
isProduction && basePathFix(),
],
build: {
outDir: 'site',
rollupOptions: {
input,
},
},
};
}
/**
* Since we deploy the site to github pages we need to prefix all the interal links with a base path
* We do this with a simple regex
*/
function basePathFix() {
return {
name: 'base-path-fix',
transformIndexHtml(html) {
// Regex matches href=", followed by a /, then any combination of \w, / or -, ending with .html
return html.replace(/href="\/([\w\/-]*)\.html/g, 'href="/$1.html');
},
};
}