-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvite.config.ts
132 lines (128 loc) · 3.86 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { writeFileSync } from 'node:fs';
import { fileURLToPath, URL } from 'node:url';
import { visualizer } from 'rollup-plugin-visualizer';
import { defineConfig, type UserConfig } from 'vite';
// eslint-disable-next-line import/default
import banner from 'vite-plugin-banner';
import { checker } from 'vite-plugin-checker';
// eslint-disable-next-line import/default
import dts from 'vite-plugin-dts';
import pkg from './package.json';
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }): UserConfig => {
const config: UserConfig = {
resolve: {
// https://vitejs.dev/config/shared-options.html#resolve-alias
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
'~': fileURLToPath(new URL('./node_modules', import.meta.url)),
},
},
// https://vitejs.dev/config/shared-options.html#base
base: './',
plugins: [
// vite-plugin-checker
// https://github.com/fi3ework/vite-plugin-checker
checker({
typescript: true,
// vueTsc: true,
}),
// vite-plugin-banner
// https://github.com/chengpeiquan/vite-plugin-banner
banner(`/**
* ${pkg.name}
*
* @description ${pkg.description}
* @author ${pkg.author.name} <${pkg.author.email}>
* @copyright 2019-${new Date().getFullYear()} By Masashi Yoshikawa All rights reserved.
* @license ${pkg.license}
* @version ${pkg.version}
* @see {@link ${pkg.homepage}}
*/
`),
// vite-plugin-dts
// https://github.com/qmhc/vite-plugin-dts
mode === 'docs'
? undefined
: dts({ tsconfigPath: './tsconfig.app.json' }),
],
// Build Options
// https://vitejs.dev/config/#build-options
build: {
outDir: mode === 'docs' ? 'docs' : undefined,
lib:
mode === 'docs'
? undefined
: {
entry: fileURLToPath(new URL('./src/Reverb.ts', import.meta.url)),
name: 'Reverb',
formats: ['umd', 'es', 'iife'],
fileName: format => `Reverb.${format}.js`,
},
rollupOptions: {
input:
mode === 'docs'
? {
'': fileURLToPath(new URL('./index.html', import.meta.url)),
localaudio: fileURLToPath(
new URL('./localaudio.html', import.meta.url)
),
}
: undefined,
plugins: [
mode === 'analyze'
? // rollup-plugin-visualizer
// https://github.com/btd/rollup-plugin-visualizer
visualizer({
open: true,
filename: 'dist/stats.html',
gzipSize: true,
brotliSize: true,
})
: undefined,
],
external:
mode === 'docs'
? []
: [
'@thi.ng/colored-noise',
'@thi.ng/random',
'@thi.ng/transducers',
],
output: {
esModule: true,
generatedCode: {
reservedNamesAsProps: false,
},
interop: 'compat',
systemNullSetters: false,
exports: 'named',
globals: {
'@thi.ng/colored-noise': 'coloredNoise',
'@thi.ng/random': 'random',
'@thi.ng/transducers': 'transducers',
},
},
},
target: 'esnext',
// minify: mode === 'docs',
},
esbuild: {
drop: command === 'serve' ? [] : ['console'],
},
};
// Write meta data.
writeFileSync(
fileURLToPath(new URL('./src/Meta.ts', import.meta.url)),
`import type MetaInterface from './interfaces/MetaInterface';
// This file is auto-generated by the build system.
const meta: MetaInterface = {
version: '${pkg.version}',
date: '${new Date().toISOString()}',
};
export default meta;
`
);
// Export vite config
return config;
});