-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetRollupConfig.js
78 lines (72 loc) · 2.13 KB
/
getRollupConfig.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
const commonjs = require('@rollup/plugin-commonjs');
const { nodeResolve: resolve } = require('@rollup/plugin-node-resolve');
const command = require('rollup-plugin-command');
const { babel } = require('@rollup/plugin-babel');
const image = require('@rollup/plugin-image');
const ignoreImport = require('rollup-plugin-ignore-import');
const path = require('path');
const tsc = require('node-typescript-compiler');
const json = require('@rollup/plugin-json');
const compileTypings = (cwd) => () => {
return tsc.compile({
project: cwd,
emitDeclarationOnly: true,
});
};
module.exports = (dirname, project) => {
const pkgPath = path.join(dirname, 'package.json');
// eslint-disable-next-line import/no-dynamic-require, global-require
const pkg = require(pkgPath);
const external = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
];
const extensions = ['.js', '.jsx', '.ts', '.tsx'];
return {
input: {
input: `${dirname}/src/index.ts`,
external: (id) => {
const moduleName = id.replace(dirname, '');
const [namespace, packageName] = moduleName.split('/');
if (namespace.startsWith('@')) {
return external.includes(`${namespace}/${packageName}`);
}
return external.includes(namespace);
},
plugins: [
command(compileTypings(project || dirname), {
exitOnFail: true,
wait: true,
}),
resolve({ extensions }),
commonjs(),
babel({
extensions,
babelHelpers: 'runtime',
include: ['src/**/*'],
rootMode: 'upward',
}),
image(),
json(),
ignoreImport({
// Ignore all .scss and .css file imports while building the bundle
extensions: ['.scss', '.css'],
}),
],
},
output: [
{
file: pkg.main,
format: 'cjs',
sourcemap: true,
// See: https://rollupjs.org/configuration-options/#output-interop
interop: 'auto',
},
{
file: pkg.module,
format: 'esm',
sourcemap: true,
},
],
};
};