forked from stalniy/casl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
103 lines (97 loc) · 2.57 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
import babel from '@rollup/plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import sourcemaps from 'rollup-plugin-sourcemaps';
function aggregate(configs, optionsOverrides) {
let external = [];
let globals = {};
if (optionsOverrides.external) {
external = optionsOverrides.external.split(',');
}
if (optionsOverrides.globals) {
globals = optionsOverrides.globals.split(',').reduce((map, chunk) => {
const [moduleId, globalName] = chunk.split(':');
map[moduleId] = globalName;
return map;
}, {});
external = external.concat(Object.keys(globals));
}
const buildVariations = process.env.BUILD_TYPES
? process.env.BUILD_TYPES.split(',')
: configs.map(config => config.id);
const buildTypes = buildVariations.reduce((types, chunk) => {
const [type, format] = chunk.split(':');
types[type] = { format };
return types;
}, {});
return configs
.filter(config => buildTypes[config.id])
.map(config => ({
external,
input: optionsOverrides.input || config.input || 'src/index.ts',
output: {
sourcemap: true,
...config.output,
globals,
format: buildTypes[config.id].format || config.output.format,
plugins: process.env.NODE_ENV === 'production' && process.env.LIB_MINIFY !== 'false'
? [terser({
mangle: {
properties: {
reserved: [
'_collection',
'__esModule',
'__forbiddenByCasl__'
],
regex: /^_[a-z]/i
}
}
})]
: []
},
plugins: [
resolve({
mainFields: ['module', 'main', 'browser'],
extensions: ['.js', '.mjs', '.ts'],
}),
process.env.ES_TRANSFORM === 'false'
? sourcemaps()
: babel({
rootMode: 'upward',
extensions: ['.js', '.mjs', '.ts'],
babelHelpers: 'bundled',
caller: {
output: config.type,
}
}),
...(config.plugins || [])
]
}));
}
export default overrideOptions => aggregate([
{
id: 'es6',
type: 'es6',
output: {
dir: 'dist/es6',
format: 'es'
},
},
{
id: 'es5m',
type: 'es5',
output: {
dir: 'dist/es5m',
format: 'es'
}
},
{
id: 'umd',
type: 'es5',
output: {
dir: 'dist/umd',
format: 'umd',
name: overrideOptions.name,
},
},
], overrideOptions);