This repository has been archived by the owner on Sep 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
66 lines (55 loc) · 1.85 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
import { promises } from 'fs';
import { resolve, dirname } from 'upath';
import babel from 'rollup-plugin-babel';
const { stat } = promises;
const extensions = ['.tsx', '.ts', '.mjs', '.jsx', '.js', '.json'];
// eslint-disable-next-line import/no-default-export
export default {
external: importee => {
return importee === 'react' || importee.startsWith('core-js') || importee.startsWith('@babel');
},
input: 'src/index.ts',
output: [
{
file: 'dist/index.esm.js',
format: 'esm',
sourcemap: true,
},
{
file: 'dist/index.cjs.js',
format: 'cjs',
sourcemap: true,
},
],
plugins: [
babel({
extensions,
runtimeHelpers: true,
}),
{
resolveId(importee, importer) {
if (!importer || !importee) return null;
const dir = dirname(importer);
// eslint-disable-next-line max-statements
const r = async (importee, importer) => {
const name = resolve(dir, importee);
for (const ext of extensions) {
try {
const stats = await stat(`${name}${ext}`);
if (stats.isFile() || stats.isSymbolicLink() || stats.isFIFO()) {
return `${name}${ext}`;
}
} catch {}
}
try {
if ((await stat(name)).isDirectory()) {
return r(resolve(dir, importee, 'index'), importer);
}
} catch {}
return null;
};
return r(importee, importer);
},
},
],
};