-
Notifications
You must be signed in to change notification settings - Fork 16
/
rollup.config.js
72 lines (64 loc) · 2.43 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
import * as path from 'path'
import typescript from 'rollup-plugin-typescript2'
import * as fsExtra from 'fs-extra'
const cwd = process.cwd()
const pkgDir = path.join(cwd, 'packages')
const cache = {}
const filter = process.env.BUILD_PKG ? process.env.BUILD_PKG.split(',').map(str => str.trim()) : null
function packageFilter(dir) {
return filter ? filter.indexOf(dir) !== -1 : dir
}
function sortByExternal({pkg: p1}, {pkg: p2}) {
const deps1 = {...p1.dependencies, ...p1.devDependencies, ...p1.peerDependencies}
const deps2 = {...p2.dependencies, ...p2.devDependencies, ...p2.peerDependencies}
if (deps1[p2.name]) return 1
if (deps2[p1.name]) return -1
return p1.name > p2.name ? -1 : (p1.name < p2.name ? 1 : 0)
}
export default fsExtra.readdir(pkgDir)
.then(dirs => Promise.all(dirs.filter(packageFilter).map(dir =>
fsExtra.readJson(path.join(pkgDir, dir, 'package.json'))
.then(pkg => ({
pkg,
pkgDir: path.join(pkgDir, dir),
srcDir: path.join(pkgDir, dir, 'src')
}))
)))
.then(
recs => recs
.sort(sortByExternal)
.map(({pkg, pkgDir, srcDir}) => ({
plugins: [
typescript({
abortOnError: true,
check: true,
exclude: ['*.spec*', '**/*.spec*'],
tsconfig: path.join(__dirname, 'tsconfig.json'),
tsconfigOverride: {
compilerOptions: {
paths: null,
rootDir: srcDir
},
include: [srcDir]
}
})
],
cache,
input: path.join(srcDir, 'index.ts'),
external: Object.keys(
Object.assign({}, pkg.devDependencies, pkg.peerDependencies, pkg.dependencies)
).concat(['path', 'fs']),
output: [
{
sourcemap: true,
format: 'es',
file: path.join(pkgDir, pkg.module)
},
{
sourcemap: true,
format: 'cjs',
file: path.join(pkgDir, pkg.main)
}
]
}))
)