hooks.js 1.0 KB

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. const { packageHotUpdate } = require('../lib/packager');
  3. const PACKAGE_NAME = 'hot-update-builder';
  4. // 让构建钩子的异常直接终止构建,避免发布一个 Manifest 或资源不完整的版本。
  5. exports.throwError = true;
  6. exports.onAfterBuild = async function onAfterBuild(options, result) {
  7. const config = options?.packages?.[PACKAGE_NAME] || {};
  8. if (!config.enabled) {
  9. return;
  10. }
  11. const summary = await packageHotUpdate({
  12. buildOptions: options,
  13. buildResult: result,
  14. remoteUrl: config.remoteUrl,
  15. version: config.version,
  16. projectPath: globalThis.Editor?.Project?.path || process.cwd(),
  17. });
  18. console.info(`[热更新打包] 完成:${summary.version}`);
  19. console.info(`[热更新打包] 本地 Manifest:${summary.localManifestPath}`);
  20. console.info(`[热更新打包] 远端资源目录:${summary.remotePackagePath}`);
  21. console.info(`[热更新打包] 文件数:${summary.fileCount},总大小:${summary.totalBytes} bytes`);
  22. };