-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
rollup.base.config.js
106 lines (95 loc) · 3.48 KB
/
rollup.base.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
import nodeResolve from "rollup-plugin-node-resolve";
import multiEntry from "rollup-plugin-multi-entry";
import cjs from "rollup-plugin-commonjs";
import replace from "rollup-plugin-replace";
import { terser } from "rollup-plugin-terser";
import sourcemaps from "rollup-plugin-sourcemaps";
import viz from "rollup-plugin-visualizer";
const pkg = require("./package.json");
const depNames = Object.keys(pkg.dependencies);
const input = "dist-esm/src/index.js";
const production = process.env.NODE_ENV === "production";
export function nodeConfig(test = false) {
const externalNodeBuiltins = ["crypto", "events", "fs"];
const baseConfig = {
input: input,
external: depNames.concat(externalNodeBuiltins),
output: { file: "dist/index.js", format: "cjs", sourcemap: true },
preserveSymlinks: false,
plugins: [
sourcemaps(),
replace({
delimiters: ["", ""],
values: {
// replace dynamic checks with if (true) since this is for node only.
// Allows rollup's dead code elimination to be more aggressive.
"if (isNode)": "if (true)"
}
}),
nodeResolve({ preferBuiltins: true }),
cjs()
]
};
if (test) {
// entry point is every test file
baseConfig.input = "dist-esm/test/**/*.spec.js";
baseConfig.input = ["dist-esm/test/*.spec.js", "dist-esm/test/node/*.spec.js"];
baseConfig.plugins.unshift(multiEntry({ exports: false }));
// different output file
baseConfig.output.file = "test-dist/index.js";
// mark assert as external
baseConfig.external.push("assert");
// Disable tree-shaking of test code. In rollup-plugin-node-resolve@5.0.0, rollup started respecting
// the "sideEffects" field in package.json. Since our package.json sets "sideEffects=false", this also
// applies to test code, which causes all tests to be removed by tree-shaking.
baseConfig.treeshake = false;
} else if (production) {
baseConfig.plugins.push(terser());
}
return baseConfig;
}
export function browserConfig(test = false, production = false) {
const baseConfig = {
input: input,
output: {
file: "browser/identity.js",
format: "umd",
name: "Azure.Identity",
sourcemap: true
},
preserveSymlinks: false,
plugins: [
sourcemaps(),
replace({
delimiters: ["", ""],
values: {
// replace dynamic checks with if (false) since this is for
// browser only. Rollup's dead code elimination will remove
// any code guarded by if (isNode) { ... }
"if (isNode)": "if (false)"
}
}),
nodeResolve({
mainFields: ["module", "browser"],
preferBuiltins: false
}),
cjs({
namedExports: { events: ["EventEmitter"] }
}),
viz({ filename: "browser/browser-stats.html", sourcemap: false })
]
};
if (test) {
baseConfig.input = "dist-esm/test/*.spec.js";
baseConfig.plugins.unshift(multiEntry({ exports: false }));
baseConfig.output.file = "test-browser/index.js";
// Disable tree-shaking of test code. In rollup-plugin-node-resolve@5.0.0, rollup started respecting
// the "sideEffects" field in package.json. Since our package.json sets "sideEffects=false", this also
// applies to test code, which causes all tests to be removed by tree-shaking.
baseConfig.treeshake = false;
} else if (production) {
baseConfig.output.file = "browser/identity.min.js";
baseConfig.plugins.push(terser());
}
return baseConfig;
}