-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.lib.ts
69 lines (66 loc) · 2.1 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import * as path from 'node:path'
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
import dts from 'vite-plugin-dts'
// https://vitejs.dev/config/
export default defineConfig({
esbuild: {
minifyIdentifiers: false, // don't mangle const names
},
build: {
lib: {
entry: './src/index.ts',
formats: ['es'],
fileName: '[name]',
},
sourcemap: true,
rollupOptions: {
external: (id) => {
// console.log(id)
return !id.startsWith('.') && !id.includes(`${process.cwd()}/src`)
},
// https://github.com/vitejs/vite/issues/5174#issuecomment-1432231710
preserveEntrySignatures: 'strict',
output: {
preserveModules: true,
},
treeshake: false,
//https://github.com/vitejs/vite/issues/5174#issuecomment-1536546402
// preserveEntrySignatures: 'strict',
// input: ['./src/index.ts'],
// output: [
// {
// dir: 'dist',
// format: 'esm',
// preserveModules: true,
// preserveModulesRoot: './src',
// entryFileNames: ({ name: fileName }) => {
// return `${fileName}.js`
// },
// },
// ],
},
},
plugins: [
react(),
dts({
tsconfigPath: 'tsconfig.build.json',
// need to transform path because it is taking it relative to the config file, not cwd
beforeWriteFile: (filePath, content) => {
// filePath: /Users/kross/projects/js/packages/concepts/dist/packages/concepts/src/index.d.ts.map
// filePath: /Users/kross/projects/js/packages/i18n/packages/i18n/src/defaultI18nextOptions.d.ts.map
const name = path.basename(process.cwd())
const search =
filePath.includes('dist') && filePath.includes('src')
? `dist/packages/${name}/src`
: `packages/${name}/src`
const replacement = `${filePath.replace(search, 'dist')}`
// console.log('filePath:', filePath, 'search:', search, 'replacement:', replacement)
return {
filePath: replacement,
content,
}
},
}),
],
})