-
Notifications
You must be signed in to change notification settings - Fork 23
/
vite.config.ts
88 lines (86 loc) · 2.58 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
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 @/components/{KongponentName} imports
'@': path.resolve(__dirname, './src/'),
'@mocks': path.resolve(__dirname, './mocks/'),
},
},
css: {
devSourcemap: true,
preprocessorOptions: {
scss: {
api: 'modern',
// Inject the @kong/design-tokens SCSS variables, kongponents variables and mixins to make them available for all components.
// This is not needed in host applications.
additionalData: `
@use "@/styles/globals" as *;
`,
},
},
},
base: process.env.USE_SANDBOX && !process.env.USE_NETLIFY ? '/kongponents/' : '/',
build: {
lib: process.env.USE_SANDBOX
? undefined
: {
entry: path.resolve(__dirname, 'src/index.ts'),
name: 'Kongponents',
fileName: (format) => `kongponents.${format}.js`,
},
minify: true,
sourcemap: !!process.env.BUILD_VISUALIZER,
rollupOptions: {
external: process.env.USE_SANDBOX ? undefined : ['vue', 'vue-router'],
output: {
globals: process.env.USE_SANDBOX
? undefined
: {
vue: 'Vue',
'vue-router': 'VueRouter',
},
exports: 'named',
},
plugins: [
// visualizer must remain last in the list of plugins
buildVisualizerPlugin,
],
},
},
optimizeDeps: {
include: [
'cypress',
'vue',
'focus-trap',
'focus-trap-vue',
],
},
server: {
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(),
})