-
Notifications
You must be signed in to change notification settings - Fork 192
/
Copy pathvite.config.lib.ts
50 lines (47 loc) · 1.08 KB
/
vite.config.lib.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
import { defineConfig, PluginOption, UserConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import pkg from './package.json';
// Banner content
const banner = `/**
* ${pkg.name}
* @version ${pkg.version}
*/\n`;
// Banner injection plugin
function bannerPlugin(): PluginOption {
return {
name: 'inject-banner',
apply: 'build',
generateBundle(_, bundle) {
for (const [, file] of Object.entries(bundle)) {
if (file.type === 'chunk' && file.fileName.endsWith('.js')) {
file.code = banner + file.code;
}
}
}
};
}
export default defineConfig({
plugins: [react(), bannerPlugin()],
build: {
lib: {
entry: path.resolve(__dirname, 'src/index.ts'),
name: 'index',
fileName: 'index',
formats: ['es'],
},
outDir: 'dist',
minify: false,
rollupOptions: {
external: [
'react',
'react-dom',
'react-dom/client',
'react/jsx-runtime'
]
}
},
define: {
__VERSION__: JSON.stringify(pkg.version),
},
} as UserConfig);