forked from n4bb12/verdaccio-github-oauth-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.js
76 lines (68 loc) · 1.78 KB
/
rollup.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
const { isAbsolute } = require("path")
const { rollup } = require("rollup")
const babel = require("rollup-plugin-babel")
const resolve = require("rollup-plugin-node-resolve")
const commonjs = require("rollup-plugin-commonjs")
const json = require("rollup-plugin-json")
const { terser } = require("rollup-plugin-terser")
async function createBundle(options) {
const { target, input, output } = options
process.env.BROWSERSLIST_ENV = target
const bundle = await rollup({
input,
plugins: [
json(),
resolve({
extensions: [".mjs", ".js", ".json", ".node", ".ts"],
preferBuiltins: false,
}),
commonjs({
include: "node_modules/**",
}),
babel({
envName: target,
extensions: [".ts"],
exclude: "node_modules/**",
}),
target === "client" && terser(),
],
external(dep) {
return !(
target === "client" ||
dep === input ||
dep.startsWith(".") ||
isAbsolute(dep)
)
},
})
await bundle.write(output)
}
async function build() {
const clientBundles = [3, 4].map(version => () =>
createBundle({
target: "client",
input: `src/client/verdaccio-${version}.ts`,
output: {
file: `dist/public/verdaccio-${version}.js`,
format: "umd",
},
}),
)
const serverBundle = () =>
createBundle({
target: "server",
input: "src/server/index.ts",
output: {
file: "dist/server.js",
format: "cjs",
exports: "named",
},
})
// FIXME:
// Do this synchronously until this PR is merged and we can use `forwardEnv`.
// https://github.com/babel/babel/pull/9161
for (const bundle of [...clientBundles, serverBundle]) {
await bundle()
}
}
build().catch(console.error)