-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
rollup.config.js
98 lines (92 loc) · 2.22 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
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-var-requires */
import path from 'path';
import { execSync } from 'child_process';
import alias from '@rollup/plugin-alias';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
import external from 'rollup-plugin-peer-deps-external';
import dts from 'rollup-plugin-dts';
const packageJson = require('./package.json');
const extensions = ['.ts', '.tsx', '.json'];
const SKNBBuildEnd = (options = {}) => {
const { hook = 'generateBundle' } = options;
return {
name: 'skn-build-end',
[hook]: async () => {
execSync('[ -d dist ] || mkdir dist');
const cmdExportTypes = 'yarn export:types';
console.log(`RUN: ${cmdExportTypes}`);
execSync(cmdExportTypes);
console.log(`DONE: ${cmdExportTypes}`);
const cmd = 'yarn export:docs';
console.log(`RUN: ${cmd}`);
execSync(cmd);
console.log(`DONE: ${cmd}`);
},
};
};
export default [
{
input: 'lib/components.ts',
external: (id) => {
return /^react|styled-jsx|next/.test(id);
},
output: [
{
file: packageJson.main,
format: 'cjs',
sourcemap: true,
name: packageJson.name,
},
{
file: packageJson.module,
format: 'esm',
sourcemap: true,
},
],
plugins: [
external(),
alias({
entries: [
{
find: '@lib',
replacement: () => {
return path.resolve(__dirname, 'lib');
},
},
],
}),
resolve({
jsnext: true,
extensions,
}),
commonjs(),
babel({
babelHelpers: 'inline',
exclude: 'node_modules/**',
extensions,
}),
SKNBBuildEnd(),
],
},
{
input: 'types/components.d.ts',
output: [{ file: packageJson.types, format: 'esm' }],
external: [/\.css$/],
plugins: [
alias({
entries: [
{
find: '@lib',
replacement: () => {
return path.resolve(__dirname, 'types/');
},
},
],
}),
dts(),
],
},
];