-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
77 lines (70 loc) · 2.08 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
import typescript from "@rollup/plugin-typescript";
import replace from "@rollup/plugin-replace";
import nodeResolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import multiInput from "rollup-plugin-multi-input";
import progress from "rollup-plugin-progress";
import json from "@rollup/plugin-json";
import { terser } from "rollup-plugin-terser";
import { string } from "rollup-plugin-string";
// Rollup is quite specific of the directory structure
// For example ".tmp-output-rollup" would break the typescript support
const INPUT = ["output-tmp-rollup/**/*.tsx", "output-tmp-rollup/**/*.ts"];
const plugins = [
multiInput({
relative: "output-tmp-rollup/",
}),
progress(),
replace({
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV),
}),
nodeResolve({
browser: true,
dedupe: ["react", "react-dom", "lodash"],
rootDir: __dirname,
}),
string({
// Required to be specified
include: "**/*.txt",
}),
commonjs(),
json(),
typescript({
tsconfig: "tsconfig.json",
sourceMap: process.env.NODE_ENV !== "production",
inlineSources: process.env.NODE_ENV !== "production",
inlineSourceMap: process.env.NODE_ENV !== "production",
}),
];
if (process.env.NODE_ENV === "production") {
plugins.push(terser());
}
export default {
input: INPUT,
watch: {
include: INPUT,
exclude: "**/*.js",
},
output: {
dir: "output",
format: "esm",
chunkFileNames: "[name].js",
sourcemap: process.env.NODE_ENV !== "production" ? "inline" : undefined,
},
manualChunks(id) {
if (id.includes("node_modules/")) {
const [_head, tail] = id.split("node_modules/");
const pathComponents = tail.split("/");
let depName = pathComponents[0];
if (tail[0] === "@") {
depName = `${pathComponents[0]}/${pathComponents[1]}`;
}
if (depName === "react" || depName === "react-dom") {
// To fix error where react-dom was loaded before react
return "dependencies/react-and-dom";
}
return `dependencies/${depName}`;
}
},
plugins,
};