forked from transloadit/uppy
/
vite.config.js
76 lines (72 loc) · 2.04 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
67
68
69
70
71
72
73
74
75
76
import { fileURLToPath } from 'node:url'
import { transformAsync } from '@babel/core'
const ROOT = new URL('../../', import.meta.url)
const PACKAGES_ROOT = fileURLToPath(new URL('./packages/', ROOT))
// To enable the plugin, it looks like we need to interact with the resolution
// algorithm, but we need to stop afterwards otherwise it messes up somewhere
// else. This hack can be removed when we get rid of JSX inside of .js files.
let counter = 0
/**
* @type {import('vite').UserConfig}
*/
const config = {
build: {
commonjsOptions: {
defaultIsModuleExports: true,
},
},
esbuild: {
jsxFactory: 'h',
jsxFragment: 'Fragment',
},
resolve: {
alias: [
{
find: /^uppy\/(.+)$/,
replacement: `${PACKAGES_ROOT}uppy/$1`,
},
{
find: /^@uppy\/([^/]+)$/,
replacement: `${PACKAGES_ROOT}@uppy/$1/src/index.js`,
},
{
find: /^@uppy\/([^/]+)\/lib\/(.+)$/,
replacement: `${PACKAGES_ROOT}@uppy/$1/src/$2`,
},
// {
// find: /^@uppy\/([^/]+)\/(.+)$/,
// replacement: PACKAGES_ROOT + "@uppy/$1/src/$2",
// },
],
},
plugins: [
// TODO: remove plugin when we switch to ESM and get rid of JSX inside .js files.
{
name: 'vite-plugin-jsx-commonjs',
// TODO: remove this hack when we get rid of JSX inside .js files.
enforce: 'pre',
// eslint-disable-next-line consistent-return
resolveId (id) {
if (id.startsWith(PACKAGES_ROOT) && id.endsWith('.js')) {
return id
}
// TODO: remove this hack when we get rid of JSX inside .js files.
if (counter++ < 2) {
return id
}
},
transform (code, id) {
if (id.startsWith(PACKAGES_ROOT) && id.endsWith('.js')) {
return transformAsync(code, {
plugins: [
['@babel/plugin-transform-react-jsx', { pragma: 'h' }],
'transform-commonjs',
],
})
}
return code
},
},
],
}
export default config