-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.js
58 lines (56 loc) · 1.77 KB
/
vite.config.js
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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import viteyaml from '@modyfi/vite-plugin-yaml'
import svgr from 'vite-plugin-svgr'
import { isAbsolute, join, resolve, relative, extname } from 'path'
import { glob } from 'glob'
import fs from 'fs'
import { fileURLToPath } from 'node:url'
import pkg from './package.json'
const isExternal = (id) => !id.startsWith('.') && !isAbsolute(id)
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), viteyaml(), svgr()],
build: {
sourcemap: true,
lib: {
entry: resolve(__dirname, 'lib/index.jsx'),
formats: ['es'],
},
rollupOptions: {
// Consider all dependencies external (do not bundle them)
external: [
/^react/,
'react-i18next',
'i18next',
'i18next-browser-languagedetector',
'prop-types',
/^dayjs/,
/^recharts/,
'styled-components',
/^@mui/,
/node_modules/,
],
// create modlue A/B/module from lib/A/B/module.jsx
input: Object.fromEntries(
glob
.sync('./lib/**/index.{ts,tsx,js,jsx}')
.map((file) => [
relative('lib', file.slice(0, file.length - extname(file).length)),
fileURLToPath(new URL(file, import.meta.url)),
]),
),
output: {
// Enable preserveModules to check any 3rd party being bundled
//preserveModules: true,
entryFileNames: '[name].[format].js',
assetFileNames: 'assets/[name]-[hash][extname]',
manualChunks: (id) => {
//if (id.includes('node_modules'))
// return id.toString().split('node_modules/')[1].split('/')[0].toString()
if (id.includes('node_modules')) return 'vendor'
},
},
},
},
})