-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathesm-loader.mjs
More file actions
26 lines (23 loc) · 854 Bytes
/
esm-loader.mjs
File metadata and controls
26 lines (23 loc) · 854 Bytes
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
// 已测试可用方案,只不过启动时需要加参数 --experimental-loader ./utils/esm-loader.mjs
// esm-loader.mjs
export async function load(url, context, nextLoad) {
// 先让 Node.js 正常加载模块
const result = await nextLoad(url, context);
// 仅处理目标模块(根据 URL 识别)
if (url.includes('/spider/catvod')) {
console.log(`自定义加载esm模块: ${url}`);
// console.log(result);
let code = result.source.toString();
// 替换 import 路径
code = code.replaceAll('assets://js/lib/', '../catLib/');
result.source = code;
return result;
// return {
// format: 'module',
// responseURL: result.responseURL,
// source: code,
// shortCircuit: true,
// };
}
return result;
}