-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathvite.config.ts
122 lines (116 loc) · 3.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { resolve as pathResolve } from 'node:path'
import react from '@vitejs/plugin-react'
import { defineConfig, type UserConfig, type UserConfigExport } from 'vite'
import svgrPlugin from 'vite-plugin-svgr'
import dts from 'vite-plugin-dts';
// https://vitejs.dev/config/
export default defineConfig(({ mode, command }) => {
const vitePlugins: UserConfig['plugins'] = [
react(),
svgrPlugin(),
dts()
]
let viteResolve: UserConfig['resolve'] = {
alias: [{ find: '@', replacement: pathResolve(__dirname, '/src') }]
}
const viteDefine: UserConfig['define'] = {}
if (mode === 'development' && command === 'serve') {
viteDefine.global = 'globalThis'
}
const viteOptimizeDeps: UserConfig['optimizeDeps'] = {
esbuildOptions: {
loader: {
'.js': 'jsx',
'.ts': 'tsx',
'.jsx': 'jsx',
'.tsx': 'tsx'
}
}
}
const viteEsBuild: UserConfig['esbuild'] = {
loader: 'tsx',
include: /\.(tsx?|jsx?)$/
}
const viteBuild: UserConfig['build'] = {
lib: {
entry: {
index: pathResolve(__dirname, 'src/index.ts'),
'providers/index': pathResolve(__dirname, 'src/providers/index.ts'),
pages: pathResolve(__dirname, 'src/pages.ts'),
forms: pathResolve(__dirname, 'src/forms.ts'),
},
name: 'ipld-explorer-components',
fileName: (format, entryName) => `${format}/${entryName}.js`,
formats: ['es']
},
outDir: 'dist',
target: 'esnext',
minify: false,
cssCodeSplit: false,
rollupOptions: {
external: [
'react',
'react-dom',
'react-i18next',
'i18next',
'i18next-browser-languagedetector',
'i18next-http-backend',
'i18next-icu',
'ipfs-css',
'tachyons',
/\.stories\..+$/,
// all test files (i.e. *.spec.{js,jsx,ts,tsx} or *.test.{js,jsx,ts,tsx})
/\.test\..+$/,
/\.spec\..+$/,
],
preserveEntrySignatures: 'strict',
input: {
index: pathResolve(__dirname, 'src/index.ts'),
'providers/index': pathResolve(__dirname, 'src/providers/index.ts'),
pages: pathResolve(__dirname, 'src/pages.ts'),
forms: pathResolve(__dirname, 'src/forms.ts'),
},
output: {
preserveModules: true,
preserveModulesRoot: 'src',
entryFileNames: '[name].js',
globals: {
react: 'React',
'react-dom': 'ReactDOM'
},
},
},
sourcemap: true,
emptyOutDir: true,
}
viteResolve = {
alias: [
{ find: /^process$/, replacement: 'rollup-plugin-node-polyfills/polyfills/process-es6' },
{ find: /^stream$/, replacement: 'rollup-plugin-node-polyfills/polyfills/stream' },
{ find: /^_stream_duplex$/, replacement: 'rollup-plugin-node-polyfills/polyfills/readable-stream/duplex' },
{ find: /^_stream_transform$/, replacement: 'rollup-plugin-node-polyfills/polyfills/readable-stream/transform' },
]
}
viteOptimizeDeps.include = []
viteOptimizeDeps.esbuildOptions = {
...viteOptimizeDeps.esbuildOptions,
plugins: []
}
const finalConfig: UserConfigExport = {
plugins: vitePlugins,
resolve: viteResolve,
define: viteDefine,
optimizeDeps: viteOptimizeDeps,
esbuild: viteEsBuild,
build: viteBuild,
server: {
open: true
},
css: {
modules: {
localsConvention: 'camelCaseOnly'
}
}
}
return finalConfig
})