-
Notifications
You must be signed in to change notification settings - Fork 8
/
vite.config.ts
90 lines (85 loc) · 2.32 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
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import yaml from '@rollup/plugin-yaml';
import * as fs from 'fs';
import * as path from 'path';
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
if (command === 'serve') {
// Development
return {
plugins: [yaml(), svelte()]
};
} else if (command === 'build') {
switch (mode) {
case 'notebook': {
// Production: notebook widget
return {
build: {
outDir: 'notebook-widget/_timbertrek',
sourcemap: false,
lib: {
entry: 'src/main-notebook.ts',
formats: ['iife'],
name: 'timbertrek',
fileName: format => 'timbertrek.js'
}
},
plugins: [
yaml(),
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, 'timbertrek.js'),
path.resolve(
__dirname,
'notebook-widget/timbertrek/timbertrek.js'
),
error => {
if (error) throw error;
}
);
// Delete all other generated files
fs.rm(options.dir, { recursive: true }, error => {
if (error) throw error;
});
}
}
}
]
};
}
case 'production': {
// Production: standard web page (default mode)
return {
build: {
outDir: 'dist'
},
plugins: [yaml(), svelte()]
};
}
case 'github': {
// Production: github page
return {
base: '/timbertrek/',
build: {
outDir: 'gh-page'
},
plugins: [yaml(), svelte()]
};
}
default: {
console.error(`Unknown production mode ${mode}`);
return null;
}
}
}
});