This repository has been archived by the owner on Feb 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
60 lines (54 loc) · 1.67 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
import dts from 'rollup-plugin-dts';
import esbuild from 'rollup-plugin-esbuild';
import rimraf from 'rimraf';
import fg from 'fast-glob';
import path from 'path';
const srcDir = './src';
const outDir = './dist';
const typesDirName = 'types';
const formats = ['esm', 'cjs'];
console.log(`removing existing outDir: ${outDir}`);
let start = +new Date();
rimraf.sync(outDir);
console.log(`done removing existing outDir, took ${+new Date() - start}ms`);
/**
* @param {string[]} entries
* @returns {import("rollup").RollupOptions[]}
*/
const createBundleFromEntries = (...entries) =>
entries
.map((entry) => entry.replace('src/', ''))
.map((entry) => [
{
input: path.join(srcDir, entry),
plugins: [esbuild({ minify: true })],
output: formats.map((format) => ({
format,
dir: path.join(outDir, format, path.parse(entry).dir),
})),
},
{
input: path.join(srcDir, entry),
plugins: [dts()],
output: { dir: path.join(outDir, typesDirName, path.parse(entry).dir) },
},
])
.flat();
const entryFilesPattern = 'src/**/*.ts';
/**
* @type {import("rollup").RollupOptions[]}
*/
const config = [
{
input: 'src/index.ts',
plugins: [esbuild({ minify: true })],
output: {
format: 'umd',
name: 'itUtils',
file: path.join(outDir, 'umd/it-utils.js'),
sourcemap: true,
esModule: false,
},
},
].concat(createBundleFromEntries.apply(null, fg.sync(entryFilesPattern)));
export default config;