This repository has been archived by the owner on Apr 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrollup.config.js
84 lines (78 loc) · 2.28 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
import { getPackages } from "@lerna/project"
import filterPackages from "@lerna/filter-packages"
import batchPackages from "@lerna/batch-packages"
import typescript from "@wessberg/rollup-plugin-ts"
import commonjs from "@rollup/plugin-commonjs"
import resolve from "@rollup/plugin-node-resolve"
import json from "@rollup/plugin-json"
import path from "path"
// import builtins from "builtin-modules"
import minimist from "minimist"
const external = [
// Textile
"@textile/threads-client",
"@textile/context",
"@textile/threads-id",
"@textile/multiaddr",
"@textile/security",
"@textile/threads",
"@textile/transport",
// Others (add externals and valid es modules here)
"stream",
]
/**
* @param {string[]}[scope] - packages to only build (if you don't
* want to build everything)
* @param {string[]}[ignore] - packages to not build
*
* @returns {Promise<any[]>} - sorted list of Package objects that
* represent packages to be built.
*/
async function getSortedPackages(scope, ignore) {
const packages = await getPackages(__dirname)
const filtered = filterPackages(packages, scope, ignore, false, true)
return batchPackages(filtered).reduce((arr, batch) => arr.concat(batch), [])
}
/**
* @returns Promise<RollupConfig>
*/
async function main() {
const config = []
// Support --scope and --ignore globs if passed in via commandline
const { scope, ignore } = minimist(process.argv.slice(2))
const packages = await getSortedPackages(scope, ignore)
packages.forEach((pkg) => {
/* Absolute path to package directory */
const basePath = path.resolve(__dirname, pkg.location)
/* Absolute path to input file */
const input = path.join(basePath, "src/index.ts")
/* Push build config for this package. */
config.push({
input,
output: [
{
exports: "named",
file: path.join(basePath, "dist/esm/index.js"),
format: "es",
},
],
external,
plugins: [
json(),
resolve({
preferBuiltins: false,
browser: true,
}),
commonjs(),
typescript(),
],
onwarn(warning, warn) {
// suppress eval warnings
if (warning.code === "EVAL") return
warn(warning)
},
})
})
return config
}
export default main()