-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy pathrolldown.config.js
More file actions
86 lines (80 loc) · 3.1 KB
/
rolldown.config.js
File metadata and controls
86 lines (80 loc) · 3.1 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { defineConfig } from 'rolldown';
import path from 'path';
import { fileURLToPath } from 'url';
import fs from 'fs';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Read extension files content
const es6ExtendContent = fs.readFileSync(path.resolve(__dirname, '../libs_drpy/es6-extend.js'), 'utf8');
const reqExtendContent = fs.readFileSync(path.resolve(__dirname, '../libs_drpy/req-extend.js'), 'utf8');
// Node.js built-in modules
const builtins = [
'assert', 'async_hooks', 'buffer', 'child_process', 'cluster', 'console',
'constants', 'crypto', 'dgram', 'dns', 'domain', 'events', 'fs', 'fs/promises',
'http', 'http2', 'https', 'inspector', 'module', 'net', 'os', 'path',
'perf_hooks', 'process', 'punycode', 'querystring', 'readline', 'repl',
'stream', 'string_decoder', 'sys', 'timers', 'tls', 'trace_events', 'tty',
'url', 'util', 'v8', 'vm', 'wasi', 'worker_threads', 'zlib'
];
export default defineConfig({
input: 'entry.js',
output: {
file: 'libs/localtDsCore.bundled.js',
format: 'esm',
sourcemap: false,
inlineDynamicImports: true,
banner: `
import { createRequire as _createRequire } from 'module';
import { fileURLToPath as _fileURLToPath } from 'url';
import { dirname as _dirname } from 'path';
const __filename = _fileURLToPath(import.meta.url);
const __dirname = _dirname(__filename);
const _originalRequire = _createRequire(import.meta.url);
const require = (moduleName) => {
if (moduleName === 'pako') return global.pako;
return _originalRequire(moduleName);
};
`,
},
platform: 'node',
treeshake: false, // Ensure no code is removed
resolve: {
conditionNames: ['node', 'import'],
alias: {
'pako': path.resolve(__dirname, '../libs_drpy/pako.min.js'),
'puppeteer': path.resolve(__dirname, 'puppeteer-mock.js')
}
},
external: (id) => {
// Check if it's a built-in module
if (builtins.includes(id) || id.startsWith('node:')) {
return true;
}
// Bundle everything else (relative paths, absolute paths, npm packages)
return false;
},
plugins: [
{
name: 'inline-extend-code',
transform(code, id) {
// Normalize path separators to handle Windows/Unix differences
const normalizedId = id.split(path.sep).join('/');
if (normalizedId.endsWith('utils/file.js')) {
let newCode = code;
// Inline es6_extend_code
// Replaces: export const es6_extend_code = readFileSync(es6JsPath, 'utf8');
newCode = newCode.replace(
/export\s+const\s+es6_extend_code\s*=\s*readFileSync\(es6JsPath,\s*['"]utf8['"]\);/,
() => `export const es6_extend_code = ${JSON.stringify(es6ExtendContent)};`
);
// Inline req_extend_code
// Replaces: export const req_extend_code = readFileSync(reqJsPath, 'utf8');
newCode = newCode.replace(
/export\s+const\s+req_extend_code\s*=\s*readFileSync\(reqJsPath,\s*['"]utf8['"]\);/,
() => `export const req_extend_code = ${JSON.stringify(reqExtendContent)};`
);
return newCode;
}
}
}
]
});