-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathvite.config.js
More file actions
73 lines (70 loc) · 1.95 KB
/
vite.config.js
File metadata and controls
73 lines (70 loc) · 1.95 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
62
63
64
65
66
67
68
69
70
71
72
73
import { defineConfig } from 'vite';
import preact from '@preact/preset-vite';
import { resolve } from 'path';
import { writeFileSync, mkdirSync } from 'fs';
// Plugin to generate HTML files at dist root after build
function generateExtensionHtml() {
return {
name: 'generate-extension-html',
closeBundle() {
// Sidepanel HTML
const sidepanelHtml = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hanzi Browse</title>
<link rel="stylesheet" href="./sidepanel.css">
</head>
<body>
<div id="app"></div>
<script type="module" src="./sidepanel.js"></script>
</body>
</html>`;
writeFileSync(resolve(__dirname, 'dist/sidepanel.html'), sidepanelHtml);
console.log('Generated dist/sidepanel.html');
// Onboarding HTML
const onboardingHtml = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome to Hanzi Browse</title>
<link rel="stylesheet" href="./onboarding.css">
</head>
<body>
<div id="app"></div>
<script type="module" src="./onboarding.js"></script>
</body>
</html>`;
writeFileSync(resolve(__dirname, 'dist/onboarding.html'), onboardingHtml);
console.log('Generated dist/onboarding.html');
}
};
}
export default defineConfig({
plugins: [preact(), generateExtensionHtml()],
base: './',
build: {
outDir: 'dist',
emptyOutDir: true,
rollupOptions: {
input: {
sidepanel: resolve(__dirname, 'src/sidepanel-preact/index.html'),
onboarding: resolve(__dirname, 'src/onboarding/index.html'),
},
output: {
entryFileNames: '[name].js',
chunkFileNames: '[name].js',
assetFileNames: '[name].[ext]',
},
},
minify: false,
sourcemap: true,
},
resolve: {
alias: {
'@': resolve(__dirname, 'src/sidepanel-preact'),
},
},
});