-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.ts
65 lines (57 loc) · 1.61 KB
/
rollup.config.ts
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
import { babel } from '@rollup/plugin-babel';
import { resolve } from 'node:path';
import { defineConfig, ModuleFormat } from 'rollup';
import { terser } from 'rollup-plugin-terser';
import ts from 'rollup-plugin-ts';
import pkg from './package.json';
const ROOT_DIR = process.cwd();
const isDev = process.env['ROLLUP_WATCH'] === 'true';
const filename = ({ mode, format }: { mode: string; format: ModuleFormat }) => {
let extension: string;
switch (format) {
case 'cjs':
case 'commonjs':
extension = 'cjs';
break;
case 'es':
case 'esm':
case 'module':
extension = 'mjs';
break;
default:
extension = 'js';
break;
}
return resolve(ROOT_DIR, 'dist', `${mode}.${extension}`);
};
const banner = ({ mode, format }: { mode: string; format: ModuleFormat }) =>
`/* ${pkg.name}@${pkg.version} (${mode} - ${format}) */`;
const serverConfig = defineConfig({
input: resolve(ROOT_DIR, 'src/server/index.ts'),
output: [
{
banner: banner({ mode: 'server', format: 'cjs' }),
file: filename({ mode: 'server', format: 'cjs' }),
format: 'cjs',
sourcemap: isDev,
},
{
banner: banner({ mode: 'server', format: 'esm' }),
file: filename({ mode: 'server', format: 'esm' }),
format: 'esm',
sourcemap: isDev,
},
],
external: ['cookie'],
plugins: [
ts(),
babel({
babelHelpers: 'bundled',
exclude: 'node_modules/**',
presets: [['@babel/env', { targets: { node: 'current' } }]],
}),
!isDev && terser({ compress: { passes: 2 } }),
],
});
const configs = [serverConfig];
export default configs;