-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvite.config.ts
101 lines (98 loc) · 3.42 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 tsconfigPaths from 'vite-tsconfig-paths';
import { PluginVisualizerOptions, visualizer } from 'rollup-plugin-visualizer';
import circleDependency from 'vite-plugin-circular-dependency';
import { resolve } from 'node:url';
const plugins = [circleDependency(), tsconfigPaths(), react()];
if (process.env.ANALYZE) {
plugins.push(
visualizer({
template: process.env
.ANALYZE as PluginVisualizerOptions['template'],
filename: `stats/${process.env.ANALYZE}.html`
})
);
}
export default defineConfig({
plugins,
resolve: {
alias: {
tslib: 'tslib/tslib.es6.js',
'react/jsx-dev-runtime.js': resolve(
__dirname,
'node_modules/react/jsx-dev-runtime.js'
),
'react/jsx-runtime.js': resolve(
__dirname,
'node_modules/react/jsx-runtime.js'
)
}
},
root: 'src',
build: {
modulePreload: false,
target: 'es2020',
outDir: '../dist/js',
emptyOutDir: true,
minify: process.env.NODE_ENV === 'production',
cssMinify: process.env.NODE_ENV === 'production',
sourcemap: process.env.NODE_ENV !== 'production',
rollupOptions: {
input: {
devtools: './src/app/devtools.ts',
panel: './src/app/panel.ts',
sandbox: './src/app/sandbox.tsx',
options: './src/app/options.tsx',
settings: './src/controllers/settings.ts',
content: './src/content/content.ts',
inject: './src/content/inject.ts',
background: './src/content/background.ts'
},
output: {
inlineDynamicImports: false,
format: 'es',
dir: './dist/js',
entryFileNames: '[name].mjs',
chunkFileNames: '[name].mjs',
assetFileNames: (info) => {
if (info.name !== 'react-vendors.css') {
return 'assets/[name]-[hash].[ext]';
}
return '[name].[ext]';
},
manualChunks(id) {
if (
id.includes('react') ||
id.includes('react-dom') ||
id.includes('react-jss') ||
id.includes('react-dnd') ||
id.includes('react-dnd-html5-backend') ||
id.includes('classnames') ||
id.includes('base16')
) {
return 'react-vendors';
}
if (id.includes('jszip')) {
return 'jszip';
}
if (id.includes('lodash')) {
return 'lodash';
}
return null;
}
}
},
assetsInlineLimit: 10 // Inline assets smaller than 4KB
},
css: {
// Configuration for CSS
},
esbuild: {
// If you were using esbuild-loader for specific loader options, you can specify esbuild options here.
},
define: {
'process.env': process.env
}
});
// NOTE: reference https://github.com/rollup/rollup/issues/2756