-
Notifications
You must be signed in to change notification settings - Fork 5
/
rollup.config.js
55 lines (49 loc) · 1.3 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
import { join, basename } from 'path';
import { readdirSync, readFileSync, statSync } from 'fs';
import terser from '@rollup/plugin-terser';
import resolve from '@rollup/plugin-node-resolve';
const PACKAGES_DIR = join('.', 'packages');
const packages = readdirSync(PACKAGES_DIR).filter((file) => {
return statSync(join(PACKAGES_DIR, file)).isDirectory();
});
export default packages.reduce((result, pkg) => {
const pkgRoot = join(PACKAGES_DIR, pkg);
const manifest = JSON.parse(
readFileSync('./' + join(pkgRoot, 'package.json')),
);
const { module, dependencies = {}, moduleName = pkg } = manifest;
return result.concat([
// CommonJS (Node)
{
input: join(pkgRoot, module),
output: {
format: 'cjs',
file: join(pkgRoot, '/build/' + basename(module)),
exports: 'default',
},
external: Object.keys(dependencies),
},
// IIFE (Browser)
{
input: join(pkgRoot, module),
output: {
format: 'iife',
name: moduleName,
file: join(pkgRoot, '/dist/' + pkg + '.js'),
exports: 'default',
},
plugins: [resolve()],
},
// IIFE (Browser, Minified)
{
input: join(pkgRoot, module),
output: {
format: 'iife',
name: moduleName,
file: join(pkgRoot, '/dist/' + pkg + '.min.js'),
exports: 'default',
},
plugins: [resolve(), terser()],
},
]);
}, []);