-
Notifications
You must be signed in to change notification settings - Fork 44
/
rollup.config.js
118 lines (111 loc) · 3.06 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
const { BUILD, ENVIRONMENT, BUILDALL } = process.env;
import resolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import typescript from '@rollup/plugin-typescript';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
const extensions = ['.js', '.ts'];
const defaultOutputOptions = {
name: 'mParticle',
strict: false,
sourcemap: ENVIRONMENT !== 'prod' ? 'inline' : false,
};
const defaultBabel = babel({
extensions,
include: ['src/**/*'],
babelHelpers: 'runtime',
});
const babelMinify = babel({
extensions,
include: ['src/**/*'],
babelHelpers: 'runtime',
babelrc: false,
presets: [
'@babel/preset-typescript',
['minify', { builtIns: false }],
['@babel/env', { modules: false }],
],
plugins: [
'@babel/proposal-class-properties',
'@babel/proposal-object-rest-spread',
'@babel/plugin-transform-runtime',
],
});
const builds = {
iife: {
input: 'src/mparticle-instance-manager.js',
output: {
...defaultOutputOptions,
file: 'dist/mparticle.js',
format: 'iife',
name: 'mParticle',
},
plugins: [
defaultBabel,
resolve(),
commonjs({
include: 'node_modules/**',
}),
typescript({ tsconfig: './tsconfig.json' }),
json(),
],
},
cjs: {
input: 'src/mparticle-instance-manager.js',
output: {
...defaultOutputOptions,
file: 'dist/mparticle.common.js',
format: 'cjs',
name: 'mParticle',
intro:
"if (typeof globalThis !== 'undefined') {globalThis.regeneratorRuntime = undefined}",
},
plugins: [
babelMinify,
resolve(),
commonjs({
include: 'node_modules/**',
}),
typescript({ tsconfig: './tsconfig.json' }),
json(),
],
},
esm: {
input: 'src/mparticle-instance-manager.js',
output: {
...defaultOutputOptions,
file: 'dist/mparticle.esm.js',
format: 'esm',
name: 'mParticle',
intro:
"if (typeof globalThis !== 'undefined') {globalThis.regeneratorRuntime = undefined}",
},
plugins: [
babelMinify,
resolve(),
commonjs({
include: 'node_modules/**',
}),
typescript({ tsconfig: './tsconfig.json' }),
json(),
],
},
stub: {
input: 'src/stub/mparticle.stub.js',
output: {
file: 'dist/mparticle.stub.js',
...defaultOutputOptions,
format: 'iife',
name: 'mParticle',
},
},
};
let selectedBuilds = [];
if (BUILDALL) {
for (let build of Object.keys(builds)) {
selectedBuilds.push(builds[build]);
}
} else {
selectedBuilds.push(builds[BUILD]);
}
export default selectedBuilds;