-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrollup.config.mjs
129 lines (111 loc) · 3.1 KB
/
rollup.config.mjs
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
import dotenv from 'dotenv';
import dotenvExpand from 'dotenv-expand';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import rollupDotenv from 'rollup-plugin-dotenv';
import resolve from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import dts from 'rollup-plugin-dts';
const env = dotenv.config();
dotenvExpand.expand(env);
const babelOptions = {
// Including JS files in the `node_modules/` directory introduces a
// large variety of cryptic errors for the CommonJS plugin. For more
// details, see:
//
// https://github.com/rollup/rollup-plugin-commonjs/issues/361#issuecomment-462943527
exclude: /node_modules/,
babelHelpers: 'runtime',
plugins: ['@babel/plugin-transform-runtime'],
presets: ['@babel/env'],
};
const commonjsOptions = {
include: /node_modules/,
};
const resolveOptions = {
// Let rollup select browser specific module versions that are
// implemented in the browser _and_ in `node` too. E.g. `crypto`.
browser: true,
};
const terserOptions = {
format: {
// Remove all comments from minified output
comments: false,
},
};
// Include sourcemaps during development
const sourcemap = process.env.NODE_ENV === 'development' ? 'inline' : false;
// Disable Tracker on MSIE 11 and below -- this banner-footer pair wraps the
// entire Tracker code which is not evaluated on MSIE 11 and below.
const banner = 'var tracker=((typeof window.document.documentMode'
+ '===\'undefined\')?(function(){';
const footer = '})():{});';
export default [{
// Browser friendly IIFE and UMD build
input: 'src/trap.js',
output: [{
file: 'dist/trap-iife.min.js',
exports: 'named',
format: 'iife',
name: 'trap',
sourcemap,
}, {
file: 'dist/trap-umd.min.js',
exports: 'named',
format: 'umd',
name: 'trap',
sourcemap,
}],
plugins: [
resolve(resolveOptions),
commonjs(commonjsOptions),
babel(babelOptions),
terser(terserOptions),
],
}, {
// CommonJS (for Node) and ES module (for bundlers) build
input: 'src/trap.js',
external: ['fflate', 'js-cookie', 'platform', 'rfdc/default', 'uuid'],
output: [{
file: 'dist/trap.min.js',
format: 'es',
sourcemap,
}, {
file: 'dist/trap-cjs.min.js',
exports: 'named',
format: 'cjs',
sourcemap,
}],
plugins: [
terser(terserOptions),
],
}, {
// Typescript Type definitions
input: 'src/trap.js',
output: [{ file: 'dist/trap.d.ts', format: 'es' }],
plugins: [
typescript(),
dts(),
],
}, {
// Browser friendly, preconfigured, IIFE tracker module
input: 'src/tracker.js',
output: [{
file: 'dist/gt.min.js',
exports: 'default', // a Tracker instance is simply available as `tracker`
format: 'iife',
name: 'tracker', // this became irrelevant, since banner/footer replaces it!
sourcemap,
// Disable MSIE 11 -- see code above
banner,
footer,
}],
plugins: [
rollupDotenv(),
resolve(resolveOptions),
commonjs(commonjsOptions),
babel(babelOptions),
terser(terserOptions),
],
}];