-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.base.mjs
72 lines (70 loc) · 2.38 KB
/
rollup.base.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
65
66
67
68
69
70
71
72
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import nodeResolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import del from 'rollup-plugin-delete';
import path from 'path';
import { readFileSync } from 'fs';
const pkg = JSON.parse(readFileSync('./package.json', { encoding: 'utf-8' }));
const defaults = {
input: 'src/index.ts',
external: [...Object.keys(pkg.peerDependencies || {}), ...Object.keys(pkg.dependencies || {})],
preserveSymlinks: true,
};
export default [
{
...defaults,
output: [
{
dir: './dist/cjs',
format: 'cjs',
sourcemap: true,
generatedCode: { constBindings: true },
preserveModules: true,
preserveModulesRoot: './src',
entryFileNames: '[name].cjs',
},
{
dir: './dist/esm',
format: 'es',
sourcemap: true,
generatedCode: { constBindings: true },
preserveModules: true,
preserveModulesRoot: './src',
entryFileNames: '[name].mjs',
},
],
plugins: [
nodeResolve({ preferBuiltins: true }),
typescript({
tsconfig: './tsconfig.lib.json',
outDir: null,
declaration: false,
declarationDir: null,
sourceMap: true,
//module: 'Node16',
}),
commonjs(),
json({ compact: true }),
del({ targets: ['dist/esm/*', 'dist/cjs/*'] }),
],
},
{
...defaults,
plugins: [
nodeResolve({ preferBuiltins: true, rootDir: path.join(process.cwd(), '../..') }),
typescript({
tsconfig: './tsconfig.lib.json',
declaration: true,
emitDeclarationOnly: true,
outDir: './dist/types',
//module: 'ESNext',
}),
commonjs(),
json({ compact: true }),
del({ targets: 'dist/types/*', hook: 'buildStart' }),
del({ targets: ['dist/types/**', '!dist/types', '!dist/types/**/*.d.ts'], hook: 'writeBundle' }),
],
output: [{ dir: 'dist/types', format: 'es', sourcemap: true }],
},
];