forked from rudderlabs/rudder-sdk-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
140 lines (134 loc) · 3.74 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
import babel from "rollup-plugin-babel";
import commonjs from "rollup-plugin-commonjs";
import resolve from "rollup-plugin-node-resolve";
import replace from "rollup-plugin-replace";
import { terser } from "rollup-plugin-terser";
import sourcemaps from "rollup-plugin-sourcemaps";
import builtins from "rollup-plugin-node-builtins";
import globals from "rollup-plugin-node-globals";
import json from "rollup-plugin-json";
import gzipPlugin from "rollup-plugin-gzip";
import brotli from "rollup-plugin-brotli";
import visualizer from "rollup-plugin-visualizer";
import * as webPackage from "./package.json";
import * as npmPackage from "./dist/rudder-sdk-js/package.json";
let distFileName = "";
let { version } = webPackage;
let moduleType = "web";
switch (process.env.ENV) {
case "prod":
switch (process.env.ENC) {
case "gzip":
if (process.env.PROD_DEBUG_INLINE == "true") {
distFileName = "dist/rudder-analytics-map.min.gzip.js";
} else {
distFileName = "dist/rudder-analytics.min.gzip.js";
}
break;
case "br":
if (process.env.PROD_DEBUG_INLINE == "true") {
distFileName = "dist/rudder-analytics-map.min.br.js";
} else {
distFileName = "dist/rudder-analytics.min.br.js";
}
break;
default:
if (process.env.PROD_DEBUG_INLINE == "true") {
distFileName = "dist/rudder-analytics-map.min.js";
} else {
distFileName = "dist/rudder-analytics.min.js";
}
break;
}
break;
default:
distFileName = "dist/browser.js";
break;
}
const outputFiles = [];
if (process.env.NPM == "true") {
outputFiles.push({
file: "dist/rudder-sdk-js/index.js",
format: "umd",
name: "rudderanalytics",
});
version = npmPackage.version;
moduleType = "npm";
} else {
outputFiles.push({
file: distFileName,
format: "iife",
name: "rudderanalytics",
sourcemap:
process.env.PROD_DEBUG_INLINE == "true"
? "inline"
: !!process.env.PROD_DEBUG,
});
}
export default {
input: "analytics.js",
external: ["Xmlhttprequest", "universal-analytics"],
output: outputFiles,
plugins: [
sourcemaps(),
replace({
"process.browser": process.env.NODE_ENV != "true",
"process.prod": process.env.ENV == "prod",
"process.package_version": version,
"process.module_type": moduleType,
}),
resolve({
jsnext: true,
browser: true,
preferBuiltins: false,
}),
commonjs({
include: "node_modules/**",
/* namedExports: {
// left-hand side can be an absolute path, a path
// relative to the current directory, or the name
// of a module in node_modules
Xmlhttprequest: ["Xmlhttprequest"]
} */
}),
json(),
globals(),
builtins(),
babel({
exclude: ["node_modules/@babel/**", "node_modules/core-js/**"],
presets: [
[
"@babel/env",
{
corejs: "3.6",
useBuiltIns: "entry",
targets: {
edge: "15",
firefox: "40",
ie: "10",
chrome: "37",
safari: "7",
opera: "23",
},
},
],
],
plugins: [
[
"@babel/plugin-proposal-class-properties",
{
loose: true,
},
],
["@babel/plugin-transform-arrow-functions"],
["@babel/plugin-transform-object-assign"],
],
}),
process.env.uglify === "true" && terser(),
process.env.ENC === "gzip" && gzipPlugin(),
process.env.ENC === "br" && brotli(),
process.env.visualizer === "true" &&
process.env.uglify === "true" &&
visualizer({ sourcemap: true }),
],
};