-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
executable file
·92 lines (81 loc) · 2.06 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
import path from 'node:path';
import ts from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';
import dts from 'rollup-plugin-dts';
import { deleteSync } from 'del';
import tsconfig from './tsconfig.json' assert { type: 'json' };
import {
isNodeOnly,
packages,
pascalName,
readPackageConfig,
} from './scripts/utils.js';
import buildConfig from './scripts/build-config.js';
// inject packages list when build
import './scripts/inject-packages-list.js';
const tsPlugin = ts({
compilerOptions: tsconfig.compilerOptions,
});
const terserPlugin = terser();
const dtsPlugin = dts();
/**
* @type {import('rollup').RollupOptions[]}
*/
const rollupOptions = [];
packages.forEach((item) => {
const name = item.name;
const pkgDir = path.join(item.path, name);
const pkgConfig = readPackageConfig(pkgDir);
const inputFile = `${pkgDir}/src/index.ts`;
const outDir = `${pkgDir}/${buildConfig.outDir}`;
// Delete output folder before build
deleteSync([`${outDir}/*`]);
/** @type {import('rollup').OutputOptions[]} */
const outputOptions = [
{
format: 'cjs',
file: `${outDir}/${name + buildConfig.ext.cjs}`,
},
{
format: 'es',
file: `${outDir}/${name + buildConfig.ext.esm}`,
},
];
// Not node env only, build for browser
if (!isNodeOnly(pkgConfig)) {
/** @type import('rollup').OutputOptions */
const base = {
name: pascalName(name),
globals: buildConfig.globals,
format: 'iife',
exports: 'named',
};
outputOptions.push(
{
...base,
file: `${outDir}/${name + buildConfig.ext.iife}`,
},
{
...base,
file: `${outDir}/${name + buildConfig.ext.iifeMin}`,
plugins: [terserPlugin],
},
);
}
rollupOptions.push(
{
input: inputFile,
output: outputOptions,
plugins: [tsPlugin],
},
{
input: inputFile,
output: {
format: 'es',
file: `${outDir}/${name + buildConfig.ext.dts}`,
},
plugins: [dtsPlugin],
},
);
});
export default rollupOptions;