-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvite.config.shared.ts
82 lines (71 loc) · 1.88 KB
/
vite.config.shared.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
import type { Plugin, UserConfig } from 'vite'
import Components from 'unplugin-vue-components/vite'
import dts from 'vite-plugin-dts'
export interface VueBridgeBuildOptions {
name: string
outDir?: string
}
const defaults: Partial<VueBridgeBuildOptions> = {
outDir: 'dist',
}
const fileExtensionMap = {
es: 'mjs',
cjs: 'cjs',
iife: 'js',
umd: 'js',
}
export const pluginsConfig = (plugins: Plugin[] = []): UserConfig['plugins'] => ([
Components({
dirs: ['src/components'],
dts: true,
}),
dts(),
...plugins,
])
export const sharedConfig = (_options = {}): UserConfig => ({
server: {
watch: {
followSymlinks: true,
},
fs: {
strict: false,
},
},
test: {
environment: 'jsdom',
deps: {
inline: true,
},
},
..._options,
})
export const buildConfig = (_options: VueBridgeBuildOptions): UserConfig['build'] => {
const options = Object.assign({}, defaults, _options)
return {
outDir: options.outDir,
lib: {
entry: 'src/main.ts',
formats: ['es', 'cjs', 'iife'],
name: options.name, // global variable name for IIFE build
// @ts-expect-error Not sure why this is invalid.
fileName: (format: keyof typeof fileExtensionMap) => {
return `index.${format}.${fileExtensionMap[format]}`
},
},
rollupOptions: {
output: {
// this means your main.ts file should only have named exports, and no default export!
exports: 'named',
// Add global names for externalized dependencies here.
// IIFE needs to now how to access external deps like: `window.Vue`
globals: {
'vue': 'Vue',
'@vue-bridge/runtime': 'VueBridge',
},
},
// add any 3rd party packages that you do no want to have bundled in your library
// this *must* contain 'vue'
external: ['vue', '@vue-bridge/runtime'],
},
}
}