-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
rollup.config.js
124 lines (108 loc) · 3.02 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
/* SPDX-FileCopyrightText: 2016-present Kriasoft <[email protected]> */
/* SPDX-License-Identifier: MIT */
import { babel } from "@rollup/plugin-babel";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import run from "@rollup/plugin-run";
import spawn from "cross-spawn";
import fs from "fs-extra";
import copy from "rollup-plugin-copy";
import del from "rollup-plugin-delete";
import "./env/config";
import pkg from "./package.json";
// AKA, development mode
const isWatch = process.env.ROLLUP_WATCH === "true";
/**
* Rollup bundler configuration.
*
* @see https://rollupjs.org/
* @type {import("rollup").RollupOptions}
*/
const config = {
input: "./api/index.ts",
output: {
dir: ".build",
format: "cjs",
sourcemap: true,
chunkFileNames: "[name].chunk.js",
},
plugins: [
del({ targets: [".build/*", ".build/.yarn/releases"], runOnce: true }),
copy({
targets: [
{
src: "views/**",
dest: ".build/views",
},
{
src: "package.json",
dest: ".build",
copyOnce: true,
transform(content) {
const pkg = JSON.parse(content);
delete pkg.scripts;
delete pkg.devDependencies;
delete pkg.envars;
return JSON.stringify(pkg, null, " ");
},
},
{
src: [".pnp.cjs", ".yarnrc.yml", "yarn.lock"],
dest: ".build",
copyOnce: true,
},
{
src: [".yarn/releases", ".yarn/plugins"],
dest: ".build/.yarn",
copyOnce: true,
},
],
copyOnce: true,
}),
nodeResolve({
extensions: [".ts", ".tsx", ".mjs", ".js", ".json", ".node"],
}),
commonjs(),
json(),
babel({
extensions: [".ts", ".tsx", ".js", ".mjs"],
babelHelpers: "bundled",
}),
!isWatch &&
replace({
"process.env.NODE_ENV": `"production"`,
preventAssignment: true,
}),
isWatch &&
run({
execArgv: ["-r", "./.pnp.cjs", "-r", "source-map-support/register"],
}),
// Prepare the output bundle for Yarn Zero-install
!isWatch && {
name: "yarn",
async writeBundle() {
await new Promise((resolve) => {
spawn("yarn", ["install"], {
stdio: ["ignore", "inherit", "ignore"],
cwd: "./.build",
env: { ...process.env, YARN_ENABLE_IMMUTABLE_INSTALLS: "false" },
}).on("exit", (code) => {
if (code !== 0) process.exit(code);
resolve();
});
});
await fs.remove(".build/.yarn/unplugged");
await fs.remove(".build/.yarn/install-state.gz");
},
},
],
external: Object.keys(pkg.dependencies),
// Suppress warnings in 3rd party libraries
onwarn(warning, warn) {
if (warning.id?.includes("node_modules")) return;
warn(warning);
},
};
export default config;