-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.mjs
64 lines (60 loc) · 1.57 KB
/
rollup.config.mjs
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
import typescript from '@rollup/plugin-typescript';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { terser } from 'rollup-plugin-terser';
import { readdirSync, statSync } from 'fs';
import { join } from 'path';
const getFiles = (dir) => {
const files = readdirSync(dir);
let fileList = [];
files.forEach((file) => {
const filePath = join(dir, file);
if (statSync(filePath).isDirectory()) {
fileList = fileList.concat(getFiles(filePath));
} else {
fileList.push(filePath);
}
});
return fileList;
};
const processorFiles = getFiles('src/processor').filter((file) =>
file.endsWith('.ts'),
);
const utilFiles = getFiles('src/util').filter((file) => file.endsWith('.ts'));
export default {
input: {
index: 'src/index.ts',
processor: 'src/processor.ts',
...processorFiles.reduce((inputs, file) => {
const relativePath = file.replace(/^src\//, '').replace(/\.ts$/, '');
inputs[relativePath] = file;
return inputs;
}, {}),
...utilFiles.reduce((inputs, file) => {
const relativePath = file.replace(/^src\//, '').replace(/\.ts$/, '');
inputs[relativePath] = file;
return inputs;
}, {}),
},
output: [
{
dir: 'dist',
format: 'cjs',
exports: 'named',
entryFileNames: '[name].js',
},
{
dir: 'dist',
format: 'esm',
entryFileNames: '[name].esm.js',
},
],
plugins: [
nodeResolve({
extensions: ['.ts', '.js'],
}),
commonjs(),
typescript(),
terser(),
],
};