-
Notifications
You must be signed in to change notification settings - Fork 6
/
rollup.config.js
98 lines (92 loc) · 2.52 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from 'rollup-plugin-typescript2';
import replace from '@rollup/plugin-replace';
import { getComponentsFolders, getFiles } from './scripts/buildUtils';
import generatePackageJson from 'rollup-plugin-generate-package-json';
const packageJson = require('./package.json');
const commonPlugins = [
replace({
preventAssignment: true,
__IS_DEV__: process.env.NODE_ENV === 'development',
}),
resolve(),
commonjs(),
typescript({
tsconfig: './tsconfig.json',
useTsconfigDeclarationDir: true,
}),
];
// Returns rollup configuration for a given component
function component(commonPlugins, folder) {
return {
input: `src/${folder}/index.ts`,
output: [
{
file: `dist/${folder}/index.esm.js`,
exports: 'named',
format: 'esm',
banner: `'use client';`,
},
{
file: `dist/${folder}/index.cjs.js`,
exports: 'named',
format: 'cjs',
banner: `'use client';`,
}
],
plugins: [
...commonPlugins,
generatePackageJson({
baseContents: {
name: `${packageJson.name}/${folder}`,
private: true,
main: './index.cjs.js',
module: './index.esm.js',
types: './index.d.ts',
peerDependencies: packageJson.peerDependencies,
},
outputFolder: `dist/${folder}/`
}),
],
// Don't bundle node_modules and ../utils
//
// We should also exclude relative imports of other components, but a trivial exclude of /\.\./ does not work
// It may require changes to the way the components are exported
external: [/node_modules/, /\.\.\/utils/],
};
}
export default [
// Build ./src/utils
{
input: getFiles('src/utils', ['js', 'ts', 'tsx']),
output: {
dir: 'dist/utils/',
format: 'esm',
},
plugins: commonPlugins,
external: [/node_modules/],
},
// Build all components in ./src/*
...getComponentsFolders('./src').map((folder) => component(commonPlugins, folder)),
// Build the main file that includes all components and utils
{
input: 'src/index.ts',
output: [
{
file: 'dist/index.esm.js',
exports: 'named',
format: 'esm',
banner: `'use client';`,
},
{
file: 'dist/index.cjs.js',
exports: 'named',
format: 'cjs',
banner: `'use client';`,
}
],
plugins: commonPlugins,
external: [/node_modules/],
},
];