forked from TuneZilla-Development/verdaccio-oidc-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.js
89 lines (79 loc) · 2.01 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
77
78
79
80
81
82
83
84
85
86
87
88
89
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 clientBundle = () =>
createBundle({
target: "client",
input: `src/client/verdaccio.ts`,
output: {
file: `dist/public/verdaccio.js`,
format: "umd",
name: `verdaccio`,
},
});
const serverBundle = () =>
createBundle({
target: "server",
input: "src/server/index.ts",
output: {
file: "dist/server.js",
format: "cjs",
exports: "named",
},
})
const cliBundle = () =>
createBundle({
target: "server",
input: "src/cli/index.ts",
output: {
file: "dist/cli.js",
format: "cjs",
exports: "named",
banner: "#!/usr/bin/env node",
},
})
// 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 [clientBundle, serverBundle, cliBundle]) {
await bundle()
}
}
build().catch(console.error)