generated from yunsii/starter-vite-react-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.lib.config.ts
66 lines (59 loc) · 1.95 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import path from 'node:path'
import { defineConfig, loadEnv, mergeConfig } from 'vite'
import dts from 'vite-plugin-dts'
import type { UserConfig } from 'vite'
import { dependencies, peerDependencies } from './package.json'
import baseConfig from './vite.base.config'
const externalPackages = [
...Object.keys(dependencies || {}),
...Object.keys(peerDependencies || {}),
]
// 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 defineConfig(({ mode }) => {
const env = loadEnv(mode, __dirname)
return mergeConfig(baseConfig, {
define: {
'process.env.VITE_FIGMA_TOKEN': `"${env.VITE_FIGMA_TOKEN}"`,
},
plugins: [dts()],
build: {
minify: false,
lib: {
entry: [
path.resolve(__dirname, 'src/plugin.ts'),
path.resolve(__dirname, 'src/extensions/local-icon-sets.ts'),
path.resolve(__dirname, 'src/extensions/figma-icon-sets/index.ts'),
path.resolve(__dirname, 'src/extensions/figma-icon-sets/node.ts'),
],
},
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',
format: 'es',
dynamicImportInCjs: true,
},
{
dir: 'dist',
preserveModules: true,
preserveModulesRoot: 'src',
entryFileNames: '[name].cjs',
format: 'cjs',
},
],
external: [...regexpsOfPackages, /^node:.*$/],
},
target: 'esnext',
},
} as UserConfig)
})