-
Notifications
You must be signed in to change notification settings - Fork 30
/
vite.config.ts
116 lines (108 loc) · 2.84 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
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
111
112
113
114
115
116
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import * as fs from 'fs';
import * as path from 'path';
// // https://vitejs.dev/config/
// export default defineConfig({
// plugins: [svelte()]
// });
const removeDataDir = () => {
return {
name: 'remove-data-dir',
resolveId(source) {
return source === 'virtual-module' ? source : null;
},
writeBundle(outputOptions, inputOptions) {
const outDir = outputOptions.dir;
const dataDir = path.resolve(outDir, 'data');
fs.rm(dataDir, { recursive: true }, () =>
console.log(`Deleted ${dataDir}`)
);
}
};
};
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
if (command === 'serve') {
// Development
return {
plugins: [svelte()]
};
} else if (command === 'build') {
switch (mode) {
case 'production': {
// Production: standard web page (default mode)
return {
build: {
outDir: 'dist'
},
plugins: [svelte()]
};
}
case 'vercel': {
// Production: for vercel demo
return {
build: {
outDir: 'dist'
},
plugins: [svelte()]
};
}
case 'github': {
// Production: github page
return {
base: '/wizmap/',
build: {
outDir: 'gh-page'
},
plugins: [svelte(), removeDataDir()]
};
}
case 'notebook': {
// Production: notebook widget
return {
build: {
outDir: 'notebook-widget/_wizmap',
sourcemap: false,
lib: {
entry: 'src/main.ts',
formats: ['iife'],
name: 'wizmap',
fileName: format => 'wizmap.js'
}
},
plugins: [
svelte({
emitCss: false
}),
{
name: 'my-post-build-plugin',
writeBundle: {
sequential: true,
order: 'post',
handler(options) {
// Move target file to the notebook package
fs.copyFile(
path.resolve(options.dir, 'wizmap.js'),
path.resolve(__dirname, 'notebook-widget/wizmap/wizmap.js'),
error => {
if (error) throw error;
}
);
// Delete all other generated files
fs.rm(options.dir, { recursive: true }, error => {
if (error) throw error;
});
}
}
}
]
};
}
default: {
console.error(`Unknown production mode ${mode}`);
return null;
}
}
}
});