-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.ts
More file actions
78 lines (76 loc) · 1.79 KB
/
vite.config.ts
File metadata and controls
78 lines (76 loc) · 1.79 KB
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
70
71
72
73
74
75
76
77
78
import * as path from 'path';
import {defineConfig, PluginOption} from 'vite';
import react from '@vitejs/plugin-react';
import linaria from '@linaria/vite';
const buildDemo = process.env.BUILD_DEMO === 'true';
const base = buildDemo ? '/react-toolroom/demos/' : '/demos/';
export default defineConfig({
base,
resolve: {
alias: [
{
find: 'react-toolroom/async',
replacement: `${path.join(__dirname, 'src/async/index.ts')}`
},
{
find: 'react-toolroom',
replacement: `${path.join(__dirname, 'src/index.ts')}`
},
{
find: /^@\/(.*)/,
replacement: `${path.join(__dirname, 'demos/$1')}`
},
{
find: /^@@\/(.*)/,
replacement: `${path.join(__dirname, 'src/$1')}`
}
]
},
define: {
'process.env.BASE_URL': JSON.stringify(base)
},
esbuild: false,
build: buildDemo
? {
outDir: 'dist/demos'
}
: {
target: false, // skip vite:esbuild-transpile
minify: 'terser',
sourcemap: true,
lib: {
name: 'react-toolroom',
entry: {
index: 'src/index.ts',
async: 'src/async/index.ts'
},
formats: ['es']
},
rollupOptions: {
external: (id) =>
!(
id.startsWith('.') ||
id.startsWith('@@/') ||
id.startsWith(`${__dirname}/src`)
)
}
},
server: {
open: '/demos/'
},
plugins: [
buildDemo
? null
: (linaria({
sourceMap: true,
exclude: ['node_modules/**']
}) as PluginOption),
react({
exclude: ['node_modules/**'],
babel: {
configFile: true,
babelrc: true
}
})
].filter((p): p is PluginOption => p !== null)
});