-
Notifications
You must be signed in to change notification settings - Fork 14
/
createRollupConfig.js
62 lines (59 loc) · 1.9 KB
/
createRollupConfig.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
import alias from '@rollup/plugin-alias'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import nodeExternals from 'rollup-plugin-node-externals'
import path from 'path'
import copy from 'rollup-plugin-copy'
export const RollupTargetEnv = Object.freeze({
BROWSER: 'browser',
NODE: 'node',
REACT_NATIVE: 'react-native'
})
const RollbarFormat = Object.freeze({
CJS: 'cjs',
ESM: 'esm'
})
export const createRollupConfig = ({ targetEnv, cwd }) =>
[RollbarFormat.CJS, RollbarFormat.ESM].map((format) => {
const extension = format === 'esm' ? 'mjs' : 'cjs'
return {
input: 'src/index.ts',
output: {
dir: path.join(cwd, 'dist', format),
format: format,
entryFileNames: ['[name]', targetEnv, extension]
.filter(Boolean)
.join('.'),
chunkFileNames: () => `[name].[hash].${extension}`
},
plugins: [
alias({
// replace `*.node.ts` imports with `*.{{env}}.ts` to create separate bundles for each environment
entries: [
{
find: /(\.)(node)/,
replacement: `$1${targetEnv}`
}
]
}),
// Uncomment when we will ready to use @uploadcare/api-client-utils as external dependency
// for browsers.
// nodeExternals({ include: /@uploadcare/ }),
nodeExternals({ exclude: /@uploadcare/ }),
nodeResolve(),
typescript({
tsconfig: path.join(cwd, 'tsconfig.build.json')
}),
// @see https://github.com/arethetypeswrong/arethetypeswrong.github.io
copy({
targets: [
{
src: path.join(cwd, 'dist', 'index.d.ts'),
dest: path.join(cwd, 'dist', format),
rename: `index.${targetEnv}.d.${format === 'esm' ? 'mts' : 'cts'}`
}
]
})
]
}
})