-
Notifications
You must be signed in to change notification settings - Fork 3
/
vite.config.ts
101 lines (95 loc) · 2.51 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
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import dts from 'vite-plugin-dts';
import svgr from 'vite-plugin-svgr';
import { visualizer } from 'rollup-plugin-visualizer';
import removeConsole from 'vite-plugin-remove-console';
import { copyFileSync, mkdirSync, existsSync, readdir } from 'fs';
function copyLocalesPlugin() {
return {
name: 'copy-locales',
closeBundle() {
const srcDir = resolve(__dirname, 'src/locales');
const destDir = resolve(__dirname, 'dist/locales');
if (!existsSync(destDir)) {
mkdirSync(destDir, { recursive: true });
}
readdir(srcDir, (err, files) => {
if (err) {
console.error(err);
return;
}
files.forEach((file) => {
if (file.endsWith('.json')) {
copyFileSync(resolve(srcDir, file), resolve(destDir, file));
}
});
});
},
};
}
export default defineConfig(({ command }) => {
const isServe = command === 'serve';
return {
root: isServe ? 'src/dev' : undefined,
plugins: [
react(),
svgr(),
!isServe &&
dts({
insertTypesEntry: true,
include: ['src'],
}),
copyLocalesPlugin(),
process.env.ANALYZE_MODE
? visualizer({
emitFile: true,
})
: undefined,
removeConsole(),
],
build: isServe
? undefined
: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
name: 'Chat',
formats: ['es', 'cjs'],
fileName: (format: string) =>
`index.${format === 'es' ? 'mjs' : 'js'}`,
},
cssCodeSplit: true,
rollupOptions: {
external: [
'react',
'react-dom',
'i18next',
'react-i18next',
'i18next-resources-to-backend',
'@appflowyinc/editor'
],
output: {
globals: {
react: 'React',
'react-dom': 'ReactDOM',
i18next: 'i18next',
'react-i18next': 'reactI18next',
'@appflowyinc/editor': 'Editor',
},
},
},
sourcemap: false,
minify: false,
},
server: {
port: 5173,
},
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
'@appflowy-chat': resolve(__dirname, 'src', 'chat'),
},
},
};
});