-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
85 lines (80 loc) · 2.21 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
import path from "path";
import typescript from "rollup-plugin-typescript2";
import replace from "@rollup/plugin-replace";
import { terser } from "rollup-plugin-terser";
import { sizeSnapshot } from "rollup-plugin-size-snapshot";
const isTesting = process.env.TESTING === "true";
const umdOptions = {
name: "Retransition",
globals: {
react: "React",
},
};
function createRollupConfig(outputDir, tsOptions, env, formats = {}) {
const { umd, cjs, es } = formats;
return {
input: "src/index.ts",
plugins: [
typescript(tsOptions),
replace({
"process.env.NODE_ENV": JSON.stringify(env),
"process.env.TESTING": JSON.stringify(isTesting),
}),
!isTesting && sizeSnapshot(),
!isTesting && terser(),
].filter(Boolean),
external: ["react"],
output: [
cjs && {
file: path.resolve(outputDir, `index.${env}.js`),
format: "cjs",
},
es && {
file: path.resolve(outputDir, "index.es.js"),
format: "es",
},
umd && {
file: path.resolve(outputDir, "index.umd.js"),
format: "umd",
...umdOptions,
sourcemap: isTesting ? "inline" : undefined,
},
].filter(Boolean),
};
}
const distDir = path.resolve(__dirname, "dist");
const ie11Dir = path.resolve(__dirname, "dist", "ie11");
const testDir = path.resolve(__dirname, "tests");
export default isTesting
? createRollupConfig(
testDir,
{
tsconfigOverride: {
compilerOptions: {
// throws error about declarationDir
declaration: false,
sourceMap: true,
inlineSourceMap: true,
inlineSources: true,
removeComments: false,
},
},
},
"production",
{ umd: true }
)
: [
createRollupConfig(distDir, undefined, "production", {
es: true,
umd: true,
cjs: true,
}),
createRollupConfig(distDir, undefined, "development", { cjs: true }),
createRollupConfig(
ie11Dir,
{ tsconfig: "tsconfig.ie11.json" },
"production",
{ es: true, umd: true, cjs: true }
),
createRollupConfig(ie11Dir, undefined, "development", { cjs: true }),
];