-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrollup.config.js
More file actions
72 lines (68 loc) · 2.23 KB
/
rollup.config.js
File metadata and controls
72 lines (68 loc) · 2.23 KB
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 esbuild from 'rollup-plugin-esbuild';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
const LicenseHeader = `#!/usr/bin/env node
/*
* pinets-cli - CLI for PineTS
* Copyright (C) 2025 Alaa-eddine KADDOURI
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/`;
const build = process.env.BUILD || 'dev';
const isProd = build === 'prod';
// Plugin to prepend the shebang + license header
function addHeader() {
return {
name: 'add-header',
generateBundle(options, bundle) {
for (const fileName in bundle) {
const chunk = bundle[fileName];
if (chunk.type === 'chunk') {
// Remove any shebang that esbuild/rollup might have added
chunk.code = chunk.code.replace(/^#!.*\n?/, '');
chunk.code = `${LicenseHeader}\n${chunk.code}`;
}
}
},
};
}
export default {
input: './src/index.ts',
output: {
file: isProd ? './dist/pinets-cli.min.cjs' : './dist/pinets-cli.dev.cjs',
format: 'cjs',
sourcemap: true,
inlineDynamicImports: true,
// Ensure the bundle is self-contained
exports: 'none',
},
plugins: [
resolve({
browser: false,
preferBuiltins: true,
mainFields: ['module', 'main'],
extensions: ['.js', '.ts', '.json'],
}),
commonjs(),
json(),
esbuild({
sourceMap: true,
minify: isProd,
treeShaking: isProd,
target: 'node18',
}),
addHeader(),
],
// Node.js built-ins are NOT bundled - they're available at runtime
external: [
'fs', 'path', 'os', 'url', 'util', 'events', 'stream', 'buffer',
'crypto', 'http', 'https', 'net', 'tls', 'zlib', 'querystring',
'child_process', 'worker_threads', 'readline',
// Node.js prefixed built-ins
/^node:/,
],
};