-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
57 lines (51 loc) · 1.24 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
import { builtinModules } from 'module';
import { resolve } from 'path';
import { pathToFileURL } from 'url';
import { rm } from 'fs/promises';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import swc from '@rollup/plugin-swc';
function cwdResolve ( name ) {
return resolve( process.cwd(), name );
}
// Remove old build folder
await rm( cwdResolve( "dist" ), { recursive: true, force: true } );
const { default: pkg } = await import( pathToFileURL( cwdResolve( "./package.json" ) ), {
with: { type: "json" },
} );
/** @type {import('rollup').RollupOptions} */
const sharedOptions = {
input: cwdResolve( "src/index.ts" ),
external: [
...builtinModules,
...Object.keys( pkg.dependencies || {} ),
...Object.keys( pkg.peerDependencies || {} ),
],
plugins: [
nodeResolve( {
browser: false,
extensions: [ '.ts', '.js', '.mts', '.mjs', '.json', '.node' ],
preferBuiltins: true
} ),
swc()
],
}
/** @type {import('rollup').RollupOptions} */
const options = [
{
output: {
file: cwdResolve( "dist/index.js" ),
format: "esm",
sourcemap: true,
},
...sharedOptions
},
{
output: {
file: cwdResolve( "dist/index.cjs" ),
format: "cjs",
sourcemap: true,
},
...sharedOptions
}
];
export default options;