-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
91 lines (74 loc) · 2.31 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
88
89
90
91
import resolve from 'rollup-plugin-node-resolve'
import replace from 'rollup-plugin-replace'
import commonjs from 'rollup-plugin-commonjs'
import babel from 'rollup-plugin-babel'
import { uglify as uglify } from 'rollup-plugin-uglify'
import { terser } from 'rollup-plugin-terser'
import gzip from 'rollup-plugin-gzip'
const configs = []
for (const pkg of ['js-surface', 'js-surface/react', 'js-surface/preact']) {
for (const format of ['umd', 'cjs', 'amd', 'esm']) {
for (const productive of [false, true]) {
configs.push(createConfig(pkg, format, productive))
}
}
}
export default configs
// --- locals -------------------------------------------------------
function createConfig(pkg, moduleFormat, productive) {
const
name = pkg.replace(/\//g, '.'),
adapter =
pkg === 'js-surface'
? 'dyo'
: pkg.replace('js-surface/', '')
let additionalReplacements = {}
if (pkg !== 'js-surface') {
additionalReplacements = {
'adaption/dyo/': `adaption/${adapter}/`,
}
}
return {
input: 'src/main/index.js',
output: {
file: productive
? `dist/${name}.${moduleFormat}.production.js`
: `dist/${name}.${moduleFormat}.development.js`,
format: moduleFormat,
name: {
'js-surface': 'jsSurface',
'js-surface/react': 'jsSurfaceReact',
'js-surface/preact': 'jsSurfacePreact'
}[pkg],
sourcemap: productive ? false : 'inline',
globals: {
'js-surface': 'jsSurface',
'js-surface/react': 'jsSurfaceReact',
'react': 'React',
'react-dom': 'ReactDOM',
'preact': 'preact',
'preact/compat': 'preactCompat',
'js-spec': 'jsSpec'
}
},
external: ['js-surface', 'react', 'react-dom', 'preact', 'preact/compat']
.concat(productive ? 'js-spec' : []),
plugins: [
resolve(),
commonjs(),
replace({
exclude: 'node_modules/**',
delimiters: ['', ''],
values: Object.assign({
'process.env.NODE_ENV': productive ? "'production'" : "'development'",
}, additionalReplacements)
}),
babel({
presets: ['@babel/preset-env'],
exclude: 'node_modules/**',
}),
productive && (moduleFormat === 'esm' ? terser() : uglify()),
productive && gzip()
],
}
}