-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
82 lines (78 loc) · 2.4 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
import { defineConfig, PluginOption } from 'vite'
import react from '@vitejs/plugin-react'
import tsconfigPaths from 'vite-tsconfig-paths'
import checker from 'vite-plugin-checker'
import eslint from 'vite-plugin-eslint'
import dns from 'dns'
import dts from 'vite-plugin-dts'
import path, { resolve } from 'path'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import fs from 'fs'
// Used to make Vite use localhost instead of 127.0.0.1
dns.setDefaultResultOrder('verbatim')
// Act as if the public folder was empty at build time (not during dev)
function removePublicFolderFromBuild (): PluginOption {
return {
name: 'remove-public-folder',
apply: 'build',
enforce: 'pre',
config(config) {
config.publicDir = false
return config
},
}
}
function autoExternals (): PluginOption {
return {
name: 'auto-externals',
apply: 'build',
enforce: 'pre',
config(config) {
const packageFile = JSON.parse((fs.readFileSync(resolve(config.root ?? './', 'package.json')).toString()))
const deps = [
...Object.keys(packageFile.dependencies || {}),
...Object.keys(packageFile.peerDependencies || {}),
...Object.keys(packageFile.devDependencies || {}),
]
const prevExternal = config.build?.rollupOptions?.external
config.build = config.build || {}
config.build.rollupOptions = config.build.rollupOptions || {}
config.build.rollupOptions.external = (...args) => {
const source = args[0]
if (typeof prevExternal === 'function' && prevExternal(...args)) return true
if (Array.isArray(prevExternal)) {
for (const x of prevExternal) {
if (typeof x === 'string' && x === source) return true
if (x instanceof RegExp && x.test(source)) return true
}
}
return deps.some(dep => source === dep || source.startsWith(`${dep}/`))
}
},
}
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
tsconfigPaths(),
checker({ typescript: true }),
eslint(),
dts({ insertTypesEntry: true }),
autoExternals(),
removePublicFolderFromBuild(),
nodeResolve()
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src')
}
},
build: {
lib: {
entry: resolve(__dirname, 'src/lib/RdfEntityViewer.tsx'),
name: 'RdfEntityViewer',
formats: ['es', 'umd']
}
},
})