-
Notifications
You must be signed in to change notification settings - Fork 11
/
rollup.config.js
91 lines (86 loc) · 1.86 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
import { builtinModules } from 'node:module';
import esbuild from 'rollup-plugin-esbuild';
import dts from 'rollup-plugin-dts';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import alias from '@rollup/plugin-alias';
import { defineConfig } from 'rollup';
import pkg from './package.json' assert { type: 'json' };
const entries = {
index: 'src/index.ts',
client: 'src/client.ts',
constants: 'src/constants.ts',
};
const external = [
...builtinModules,
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
'pathe',
'birpc',
'vite',
'vite/types/hot',
'node:url',
'node:events',
'node:vm',
];
const plugins = [
resolve({
preferBuiltins: true,
}),
json(),
commonjs(),
esbuild({
target: 'node14',
}),
];
export default defineConfig([
{
input: entries,
output: {
dir: 'dist',
format: 'esm',
entryFileNames: '[name].mjs',
chunkFileNames: 'chunk-[name].mjs',
},
external,
plugins,
onwarn,
},
{
input: entries,
output: {
dir: 'dist',
format: 'cjs',
entryFileNames: '[name].cjs',
chunkFileNames: 'chunk-[name].cjs',
},
external,
plugins: [
alias({
entries: [
// cjs in Node 14 doesn't support node: prefix
// can be dropped, when we drop support for Node 14
{ find: /^node:(.+)$/, replacement: '$1' },
],
}),
...plugins,
],
onwarn,
},
{
input: entries,
output: {
dir: 'dist',
entryFileNames: '[name].d.ts',
format: 'esm',
},
external,
plugins: [dts({ respectExternal: true })],
onwarn,
},
]);
function onwarn(message) {
if (['EMPTY_BUNDLE', 'CIRCULAR_DEPENDENCY'].includes(message.code)) return;
console.error(message);
}