This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.ts
82 lines (73 loc) · 1.92 KB
/
rollup.config.ts
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
79
80
81
82
import * as path from 'path';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import babel from 'rollup-plugin-babel';
import builtins from 'builtins';
process.env.BABEL_ENV = process.env.NODE_ENV = 'production';
const pkg = require(path.resolve(process.cwd(), 'package.json'));
const externalModules = [
...Object.keys(pkg.peerDependencies || {}),
...Object.keys(pkg.dependencies || {}),
...(pkg.bin ? builtins('13.0.0') : [])
];
export default {
input: 'src/index.ts',
external: id => {
// Bare module identifier
if (!id.includes('/')) {
return true;
}
// Relative path
if (id.startsWith('.')) {
return false;
}
// These are absolute paths
if (id.includes('babel-runtime')) {
return true;
}
if (externalModules.includes(id)) {
return true;
}
const packageName = id
.split('node_modules')
.pop()
.split('/')
.shift();
if (!packageName) {
return false;
}
return externalModules.includes(packageName);
},
output: [
pkg.main && { file: pkg.main, format: 'cjs' },
pkg.module && { file: pkg.module, format: 'es' },
pkg.unpkg && { name: pkg.name, file: pkg.unpkg, format: 'umd' }
].filter(Boolean),
plugins: [
babel({
runtimeHelpers: true,
configFile: path.join(__dirname, 'babel.config.js'),
extensions: ['.ts', '.tsx', '.js']
}),
resolve({
extensions: ['.ts', '.tsx', '.js']
}),
commonjs({
namedExports: {
'@storybook/react': ['addDecorator'],
'@storybook/theming': ['withTheme'],
'@storybook/components': ['ActionBar'],
'@storybook/addons': ['makeDecorator'],
react: [
'createContext',
'createElement',
'Component',
'Fragment',
'forwardRef'
]
}
}),
json()
]
};