-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathvite.config.js
66 lines (63 loc) · 1.75 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
59
60
61
62
63
64
65
66
const defineViteConfig = require('vite').defineConfig
const react = require('@vitejs/plugin-react').default
const nodeResolve = require('@rollup/plugin-node-resolve').default
const path = require('path')
const viteExternalsPlugin = require('vite-plugin-externals').viteExternalsPlugin
const { FIFTYONE_DIR } = process.env
const dir = __dirname
const IS_DEV = process.env.IS_DEV === 'true'
function fiftyonePlugin() {
if (!FIFTYONE_DIR) {
throw new Error(
`FIFTYONE_DIR environment variable not set. This is required to resolve @fiftyone/* imports.`
)
}
return {
name: 'fiftyone-rollup',
resolveId: {
order: 'pre',
async handler(source) {
if (source.startsWith('@fiftyone')) {
const pkg = source.split('/')[1]
const modulePath = `${FIFTYONE_DIR}/app/packages/${pkg}`
return this.resolve(modulePath, source, { skipSelf: true })
}
return null
}
}
}
}
const package = require(`${dir}/package.json`)
module.exports = defineViteConfig({
mode: 'development',
plugins: [
fiftyonePlugin(),
nodeResolve(),
react(),
viteExternalsPlugin({
react: 'React',
'react-dom': 'ReactDOM',
recoil: 'recoil',
'@fiftyone/state': '__fos__',
'@fiftyone/operators': '__foo__',
'@fiftyone/components': '__foc__',
'@fiftyone/utilities': '__fou__',
'@mui/material': '__mui__' // use mui from fiftyone
})
],
build: {
minify: IS_DEV ? false : true,
lib: {
entry: path.join(dir, package.main),
name: package.name,
fileName: (format) => `index.${format}.js`,
formats: ['umd']
}
},
define: {
'process.env.NODE_ENV': '"development"'
},
optimizeDeps: {
exclude: ['react', 'react-dom']
}
})