-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
42 lines (40 loc) · 1.09 KB
/
vite.config.ts
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
import { resolve } from 'path';
import { defineConfig } from 'vite';
import { VitePWA } from 'vite-plugin-pwa';
import { htmlInjectHead } from './build-helper/html-head';
import { htmlInjectFooter } from './build-helper/html-footer';
/**
* HTML Build replacing
* @example '<template data-replace-key="injectHtmlHead"></template>'
* @param data
* @returns {{transformIndexHtml(html: string): any, name: string, order: string}}
*/
const transformHtmlPlugin = data => ({
name: 'html-transform',
order: 'pre',
transformIndexHtml(html: string) {
const regex = /<template\s+data-replace-key="([^"]+)"><\/template>/gi;
return html.replace(
regex,
(match, p1) => data[p1] || ''
);
},
});
export default defineConfig({
plugins: [
transformHtmlPlugin({
injectHtmlHead: htmlInjectHead,
injectHtmlFooter: htmlInjectFooter,
}),
VitePWA({ registerType: 'autoUpdate' }),
],
appType: 'mpa',
build: {
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
vita: resolve(__dirname, 'vita/index.html'),
},
},
},
});