manifestJson.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.uniManifestJsonPlugin = void 0;
  7. const path_1 = __importDefault(require("path"));
  8. const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
  9. function uniManifestJsonPlugin() {
  10. return (0, uni_cli_shared_1.defineUniManifestJsonPlugin)((opts) => {
  11. const inputDir = process.env.UNI_INPUT_DIR;
  12. return {
  13. name: 'uni:app-manifest-json',
  14. enforce: 'pre',
  15. transform(code, id) {
  16. if (!opts.filter(id)) {
  17. return;
  18. }
  19. this.addWatchFile(path_1.default.resolve(inputDir, 'manifest.json'));
  20. (0, uni_cli_shared_1.getLocaleFiles)(path_1.default.resolve(inputDir, 'locale')).forEach((filepath) => {
  21. this.addWatchFile(filepath);
  22. });
  23. const manifestJson = (0, uni_cli_shared_1.normalizeAppManifestJson)((0, uni_cli_shared_1.parseJson)(code), (0, uni_cli_shared_1.parsePagesJsonOnce)(inputDir, process.env.UNI_PLATFORM));
  24. // 生成一个空的 app-config.js,兼容基座已有规范
  25. this.emitFile({
  26. fileName: uni_cli_shared_1.APP_CONFIG,
  27. type: 'asset',
  28. source: '(function(){})();',
  29. });
  30. this.emitFile({
  31. fileName: `manifest.json`,
  32. type: 'asset',
  33. source: JSON.stringify(manifestJson, null, 2),
  34. });
  35. return {
  36. code: '',
  37. map: null,
  38. };
  39. },
  40. };
  41. });
  42. }
  43. exports.uniManifestJsonPlugin = uniManifestJsonPlugin;