-
Notifications
You must be signed in to change notification settings - Fork 25
/
rollup.config.js
87 lines (74 loc) · 1.8 KB
/
rollup.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
77
78
79
80
81
82
83
84
85
86
87
// rollup.config.js
import babel from '@rollup/plugin-babel'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import { terser } from 'rollup-plugin-terser'
import serve from 'rollup-plugin-serve'
import copy from 'rollup-plugin-copy'
const IS_TEST = process.env.NODE_ENV === 'test-rollup'
const IS_WATCH = process.argv.includes('--watch')
const MINIFY = terser()
// Modern builds will not bundle dependencies
const PLUGINS = [resolve({ browser: true }), commonjs()]
const BABEL = babel({
exclude: 'node_modules/**',
babelHelpers: 'bundled'
})
const DEFAULTS = {
input: 'index.js',
external: ['react', 'react-dom', 'react-dom/client']
}
const UMD = {
format: 'umd',
name: 'Remount',
globals: { react: 'React', 'react-dom/client': 'ReactDOM' }
}
const SERVE_PLUGINS = IS_WATCH
? [
serve({
// open: true,
contentBase: 'dist',
port: +(process.env.PORT || 10049)
})
]
: []
const TEST_MODULES = IS_TEST
? [
{
input: 'test/browser_test.js',
plugins: [
BABEL,
copy({
'test/index.html.template': 'dist/index.html'
}),
...SERVE_PLUGINS
],
output: { file: 'dist/browser_test.js', format: 'cjs' }
}
]
: []
export default [
// ES Modules
{
...DEFAULTS,
plugins: [...PLUGINS],
output: { file: 'dist/remount.js', format: 'esm' }
},
{
...DEFAULTS,
plugins: [...PLUGINS, MINIFY],
output: { file: 'dist/remount.min.js', format: 'esm' }
},
// ES5
{
...DEFAULTS,
plugins: [...PLUGINS, BABEL],
output: { file: 'dist/remount.es5.js', ...UMD }
},
{
...DEFAULTS,
plugins: [...PLUGINS, BABEL, MINIFY],
output: { file: 'dist/remount.es5.min.js', ...UMD }
},
...TEST_MODULES
]