-
Notifications
You must be signed in to change notification settings - Fork 5
/
rollup.config.js
141 lines (129 loc) · 2.63 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import path from 'path'
import { mergeWith } from 'lodash'
import alias from '@rollup/plugin-alias'
import typescript from 'rollup-plugin-typescript2'
import { terser } from 'rollup-plugin-terser'
import baseConfig from './rollup.config.base'
const noLodash = merge(
{
plugins: [
alias({
entries: [{ find: 'lodash', replacement: resolve('tools/lodash.ts') }],
}),
],
},
baseConfig
)
const lodashES = merge(
{
plugins: [
alias({
entries: [{ find: 'lodash', replacement: 'lodash-es' }],
}),
],
},
baseConfig
)
const tsCompile = typescript({
tsconfigOverride: {
compilerOptions: {
module: 'es2015',
declaration: false,
declarationMap: false,
},
},
})
const umdConfig = merge(noLodash, {
output: {
format: 'umd',
name: 'jsTree',
},
plugins: [
typescript({
tsconfigOverride: {
compilerOptions: {
target: 'es5',
module: 'es2015',
declaration: false,
declarationMap: false,
removeComments: true,
},
},
}),
],
})
export default [
// CommonJS
merge(noLodash, {
output: {
format: 'cjs',
file: resolve('./dist/js.tree.common.js'),
},
plugins: [tsCompile],
}),
merge(baseConfig, {
output: {
format: 'cjs',
file: resolve('./dist/js.tree.common.lodash.js'),
},
plugins: [
typescript({
tsconfigOverride: {
compilerOptions: {
module: 'es2015',
},
},
}),
],
}),
// ES Module
merge(noLodash, {
output: {
format: 'esm',
file: resolve('./dist/js.tree.esm.js'),
},
plugins: [tsCompile],
}),
merge(baseConfig, {
output: {
format: 'esm',
file: resolve('./dist/js.tree.esm.lodash.js'),
},
plugins: [tsCompile],
}),
merge(lodashES, {
output: {
format: 'esm',
file: resolve('./dist/js.tree.esm.lodash-es.js'),
},
plugins: [tsCompile],
}),
// UMD
merge(umdConfig, {
output: {
file: resolve('./dist/js.tree.js'),
},
}),
merge(umdConfig, {
output: {
sourcemap: true,
file: resolve('./dist/js.tree.min.js'),
},
plugins: [terser()],
}),
]
function resolve(filename) {
return path.join(__dirname, filename)
}
function merge(object, sources) {
return mergeWith({ ...object }, sources, function (objValue, srcValue, key) {
switch (key) {
case 'output':
return Object.assign({}, objValue, srcValue)
case 'plugins':
return (objValue || []).concat(srcValue || [])
default:
return srcValue || objValue
}
})
}