generated from yunsii/starter-vite-react-library
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.lib.config.ts
50 lines (43 loc) · 1.32 KB
/
vite.lib.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
import path from 'node:path'
import fse from 'fs-extra'
import { mergeConfig } from 'vite'
import dts from 'vite-plugin-dts'
import baseConfig from './vite.base.config'
import type { UserConfig } from 'vite'
const { peerDependencies = {}, dependencies = {} } =
fse.readJsonSync('./package.json')
const externalPackages = Array.from(
new Set([...Object.keys(peerDependencies), ...Object.keys(dependencies)]),
)
// Creating regexps of the packages to make sure subpaths of the
// packages are also treated as external
const regexpsOfPackages = externalPackages.map(
(packageName) => new RegExp(`^${packageName}(/.*)?`),
)
// https://vitejs.dev/config/
export default mergeConfig(baseConfig, {
plugins: [
dts({
exclude: ['**/demos'],
}),
],
build: {
minify: false,
lib: {
entry: path.resolve(__dirname, 'src/index.ts'),
formats: ['es'],
},
rollupOptions: {
// inspired from: https://github.com/vitejs/vite/discussions/1736#discussioncomment-2621441
// preserveModulesRoot: https://rollupjs.org/guide/en/#outputpreservemodulesroot
output: {
dir: 'dist',
preserveModules: true,
preserveModulesRoot: 'src',
entryFileNames: '[name].mjs',
},
external: [...regexpsOfPackages, /^node:.*$/],
},
target: 'esnext',
},
} as UserConfig)