-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrollup.config.js
More file actions
60 lines (55 loc) · 1.98 KB
/
Copy pathrollup.config.js
File metadata and controls
60 lines (55 loc) · 1.98 KB
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
import path from 'path';
import minimist from 'minimist';
import { getPackages } from '@lerna/project';
import { filterPackages } from '@lerna/filter-packages';
import batchPackages from '@lerna/batch-packages';
import copy from 'rollup-plugin-copy';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
async function getSortedPackages(scope, ignore) {
const packages = await getPackages(__dirname);
const filtered = filterPackages(packages, scope, ignore, false);
return batchPackages(filtered).reduce((arr, batch) => arr.concat(batch), []);
}
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.relative(__dirname, pkg.location);
/* Absolute path to input file */
const input = path.join(basePath, 'src/index.js');
/* "main" field from package.json file. */
const {
exports: { import: esPath, require: cjsPath },
} = pkg.toJSON();
/* Push build config for this package. */
config.push({
input,
output: [
{
file: path.join(basePath, cjsPath),
format: 'cjs',
},
{
file: path.join(basePath, esPath),
format: 'es',
},
],
// all dependencies should be listed as external
external: [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})],
// copy the ts declaration file into the dist folder
plugins: [
babel({ babelHelpers: 'bundled' }),
nodeResolve(),
commonjs(),
copy({ targets: [{ src: path.join(basePath, 'src/index.d.ts'), dest: path.join(basePath, 'dist') }] }),
],
});
});
return config;
}
export default main();