-
Notifications
You must be signed in to change notification settings - Fork 4
/
rollup.config.js
104 lines (98 loc) · 2.21 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
99
100
101
102
103
104
import { exec } from 'child_process';
import glob from 'glob';
import path from 'path';
import { babel } from "@rollup/plugin-babel";
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from 'rollup-plugin-ts';
import terser from '@rollup/plugin-terser';
import copy from 'rollup-plugin-copy';
import pkg from './package.json' assert { type: 'json' };
/** Custom rollup plugin to exec tsc-alias over the built files */
function tscAliasPlugin() {
return {
name: 'tsc-alias',
writeBundle: () => {
return new Promise((resolve, reject) => {
exec('tsc-alias', function callback(error, stdout, stderr) {
if (stderr || error) {
reject(stderr || error);
} else {
resolve(stdout);
}
});
});
}
};
}
/**
* Plugin to watch extra files in rollup.js
*
* @param globs string[]
*/
function watcher(globs) {
/** @type {import('rollup').Plugin} */
const hook = {
buildStart() {
for (const item of globs) {
glob.sync(path.resolve(item)).forEach((filename) => {
this.addWatchFile(filename);
});
}
}
};
return hook;
}
/** @type {import('rollup').RollupOptions} */
const buildConfig = {
input: 'src/index.ts',
output: [
{
file: pkg.module,
format: 'esm',
sourcemap: true
},
{
file: pkg.main,
format: 'cjs',
sourcemap: true
}
],
plugins: [
watcher(['./src/styles.css']),
peerDepsExternal(),
nodeResolve(),
commonjs(),
babel({
exclude: "node_modules/**",
presets: ["@babel/preset-react"],
}),
typescript({
tsconfig: './tsconfig.json',
sourceMap: true
}),
tscAliasPlugin(),
copy({
targets: [
{
src: './src/styles.css',
dest: './dist'
},
]
})
]
};
/** @type {import('rollup').RollupOptions} */
const browserConfig = {
input: 'dist/index.js',
output: [
{
file: pkg.unpkg,
format: 'umd',
name: 'Dropdown',
}
],
plugins: [terser()]
};
export default [buildConfig, browserConfig];