-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
73 lines (68 loc) · 2.46 KB
/
vite.config.js
File metadata and controls
73 lines (68 loc) · 2.46 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 { resolve } from 'path'
export default defineConfig(({ command }) => {
const isStandalone = process.env.BUILD_STANDALONE === 'true'
if (isStandalone) {
// Standalone IIFE build for file:// protocol compatibility
return {
build: {
outDir: 'dist',
minify: false, // Ensure source remains readable for field debugging
base: './', // Use relative paths
assetsInlineLimit: 100000, // Inline smaller assets as base64
cssCodeSplit: false, // Bundle CSS into JS
rollupOptions: {
input: resolve(__dirname, 'src/index.js'),
output: {
format: 'iife',
name: 'GramFrame',
inlineDynamicImports: true,
entryFileNames: 'gramframe.bundle.js',
assetFileNames: '[name][extname]'
},
plugins: [
{
name: 'inline-css',
generateBundle(options, bundle) {
const cssFiles = Object.keys(bundle).filter(filename => filename.endsWith('.css'))
const jsFiles = Object.keys(bundle).filter(filename => filename.endsWith('.js'))
if (cssFiles.length > 0 && jsFiles.length > 0) {
const cssContent = cssFiles.map(filename => bundle[filename].source).join('\n')
const jsFile = bundle[jsFiles[0]]
// Inject CSS at the beginning of the IIFE
jsFile.code = jsFile.code.replace(
'(function() {',
`(function() {
// Inject CSS styles
const style = document.createElement('style');
style.textContent = ${JSON.stringify(cssContent)};
document.head.appendChild(style);
`
)
// Delete CSS files from bundle
cssFiles.forEach(filename => delete bundle[filename])
}
}
}
]
}
}
}
} else {
// Standard development build
return {
build: {
outDir: 'dist',
minify: false, // Ensure source remains readable for field debugging
rollupOptions: {
input: {
index: resolve(__dirname, 'index.html'),
main: resolve(__dirname, 'sample/index.html'),
debug: resolve(__dirname, 'debug.html'),
'debug-trainer': resolve(__dirname, 'debug-trainer.html')
}
}
}
}
}
})