-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
56 lines (51 loc) · 1.88 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
import { resolve } from 'path'
import { defineConfig, loadEnv } from 'vite'
import { svelte } from '@sveltejs/vite-plugin-svelte'
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js';
import * as pkg from './package.json'
// https://vitejs.dev/config/
export default defineConfig((props) => {
// loads env variables based on the build mode (production|dev)
// loads only variables prefixed with APP_
const env = loadEnv(props.mode, process.cwd(), 'APP_')
// builds output based on the env's build_target
// if no build_target is passed, the main.ts will be built as tc-universal-nav
const target = env.APP_BUILD_TARGET as 'nudge' | undefined;
const entry = !env.APP_BUILD_TARGET ? 'main' : `out/${target}`
const outputFileName = `${target ?? 'tc-universal-nav'}`
return {
define: {
BUILD_IS_PROD: props.mode === 'production',
},
plugins: [
cssInjectedByJsPlugin(),
svelte(),
],
resolve: {
alias: {
assets: resolve(__dirname, './src/assets'),
lib: resolve(__dirname, './src/lib'),
}
},
build: {
// there are 3 separate build processes
// running in parallel
// need to keep the output dir contents intact
// otherwise the last build process will remove the other outputs
emptyOutDir: false,
// this doesn't remove whitespaces
minify: true,
lib: {
entry: resolve(__dirname, `src/${entry}.ts`),
formats: ['es'],
fileName: outputFileName
},
outDir: `dist/v${pkg.version.split('.')[0]}`,
rollupOptions: {
output: {
manualChunks: () => `${outputFileName}.js`
},
},
},
}
})