-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
92 lines (90 loc) · 2.6 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
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import VueDevTools from 'vite-plugin-vue-devtools'
import path, { join } from 'path'
import { visualizer } from 'rollup-plugin-visualizer'
// Include the rollup-plugin-visualizer if the BUILD_VISUALIZER env var is set to "true"
const buildVisualizerPlugin = process.env.BUILD_VISUALIZER
? visualizer({
filename: path.resolve(__dirname, 'bundle-analyzer/stats-treemap.html'),
template: 'treemap', // sunburst|treemap|network
sourcemap: true,
gzipSize: true,
})
: undefined
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
vue(),
VueDevTools(),
],
resolve: {
alias: {
// Alias src directory for imports
'@': path.resolve(__dirname, './src/'),
},
},
css: {
devSourcemap: true,
preprocessorOptions: {
scss: {
// Inject the @kong/design-tokens SCSS variables to make them available for all components.
// This is not needed in host applications.
additionalData: '@import "@kong/design-tokens/tokens/scss/variables";',
},
},
},
base: process.env.USE_SANDBOX ? '/icons/' : '/',
build: {
lib: process.env.USE_SANDBOX
? undefined
: {
entry: path.resolve(__dirname, 'src/index.ts'),
name: 'KongIcons',
fileName: (format) => {
if (format === 'cjs') {
return 'kong-icons.cjs'
} else {
return `kong-icons.${format}.js`
}
},
formats: ['es', 'cjs'],
},
emptyOutDir: true,
minify: true,
sourcemap: true,
rollupOptions: {
external: process.env.USE_SANDBOX ? undefined : ['vue'],
output: process.env.USE_SANDBOX
? undefined
: {
globals: {
vue: 'Vue',
},
exports: 'named',
preserveModules: true,
preserveModulesRoot: 'src',
inlineDynamicImports: false,
},
plugins: [
// visualizer must remain last in the list of plugins
buildVisualizerPlugin,
],
},
},
optimizeDeps: {
include: [
'vue',
],
},
server: {
open: !!process.env.USE_SANDBOX,
fs: {
// Allow serving files from one level up from the package root - IMPORTANT - to support the sandbox
allow: [join(__dirname, '..')],
},
},
// Change the root when utilizing the sandbox via USE_SANDBOX=true to use the `/sandbox/*` files
// During the build process, the `/sandbox/*` files are not used and we should default to the package root.
root: process.env.USE_SANDBOX ? './sandbox' : process.cwd(),
})