This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
110 lines (97 loc) · 2.18 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/** @format */
// noinspection JSUnusedGlobalSymbols
// Why do I need to write this import statement?
import { readFileSync, writeFileSync } from 'fs';
import { parse } from 'node-html-parser';
process.env.BROWSER = 'C:\\Program Files\\Google\\Chrome Dev\\Application\\chrome.exe';
export const fixHtmlHead = () => {
// noinspection JSUnusedGlobalSymbols
return {
name: 'vite-plugin-fixHtmlHead',
closeBundle: async () => {
await (() => {
const html = parse(readFileSync('docs/index.html', { encoding: 'utf-8' }));
html
.querySelector('[src="/assets/index.js"]')
.removeAttribute('crossorigin');
html
.querySelector('[href="/assets/style.css"]')
.setAttribute('blocking', 'render');
writeFileSync('docs/index.html', html.toString());
})();
},
};
};
export default {
//region Shared Options
root: 'src',
css: {
preprocessorOptions: {
scss: {
OutputStyle: 'expanded',
},
},
},
esbuild: {
minifyIdentifiers: false,
minifySyntax: false,
},
clearScreen: false,
//endregion
//region Server Options
server: {
host: true,
strictPort: true,
open: 'index.html',
fs: {
strict: false,
allow: [
'index.html',
'M/index.css',
'M/index.mjs',
],
},
},
//endregion
//region Build Options
build: {
target: 'esnext',
modulePreload: false,
// For GitHub pages "classic experience".
emptyOutDir: false,
outDir: '../docs',
assetsInlineLimit: 0,
cssCodeSplit: false,
reportCompressedSize: false,
rollupOptions: {
output: {
entryFileNames: 'assets/[name].js',
chunkFileNames: 'assets/[name].js',
assetFileNames: 'assets/[name].[ext]',
},
},
},
//endregion
//region Preview Options
preview: {
host: true,
strictPort: true,
open: 'index.html',
},
//endregion
//region Dep Optimization Options
optimizeDeps: {
entries: ['index.html'],
force: true,
},
//endregion
//region Plugins
plugins: [
{
...fixHtmlHead(),
enforce: 'post',
apply: 'build',
},
],
//endregion
};