-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
61 lines (59 loc) · 1.68 KB
/
vite.config.js
File metadata and controls
61 lines (59 loc) · 1.68 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
import { defineConfig } from 'vite'
import wasm from 'vite-plugin-wasm'
import topLevelAwait from 'vite-plugin-top-level-await'
import { resolve } from 'path'
import { copyFileSync, mkdirSync } from 'fs'
// Copy WASM files from pkg to public
try {
mkdirSync('public/wasm', { recursive: true });
mkdirSync('public/js', { recursive: true });
copyFileSync('pkg/terraphim_editor_bg.wasm', 'public/wasm/terraphim_editor_bg.wasm');
copyFileSync('pkg/terraphim_editor.js', 'public/js/terraphim_editor.js');
} catch (error) {
console.error('Error copying files:', error);
}
export default defineConfig({
plugins: [
wasm(),
topLevelAwait()
],
build: {
outDir: 'dist',
target: 'esnext',
lib: {
entry: resolve(__dirname, 'public/js/terraphim-editor.js'),
name: 'TeraphimEditor',
formats: ['es', 'umd', 'iife'],
fileName: (format) => {
switch (format) {
case 'es':
return 'js/terraphim-editor.mjs'
case 'umd':
return 'js/terraphim-editor.umd.js'
case 'iife':
return 'js/terraphim-editor.iife.js'
default:
return 'js/terraphim-editor.js'
}
}
},
rollupOptions: {
external: ['./config.js'],
output: {
globals: {
'./config.js': 'TeraphimConfig'
},
assetFileNames: (assetInfo) => {
if (assetInfo.name === 'style.css') return 'css/terraphim-editor.css'
if (assetInfo.name.endsWith('.wasm')) return 'wasm/[name][extname]'
return '[ext]/[name][extname]'
}
}
},
sourcemap: true,
minify: 'esbuild'
},
optimizeDeps: {
exclude: ['./config.js']
}
})