pagesJson.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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.uniAppPagesPlugin = void 0;
  7. const path_1 = __importDefault(require("path"));
  8. const fs_extra_1 = __importDefault(require("fs-extra"));
  9. const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
  10. const utils_1 = require("../utils");
  11. function uniAppPagesPlugin() {
  12. const pagesJsonPath = path_1.default.resolve(process.env.UNI_INPUT_DIR, 'pages.json');
  13. const pagesJsonUTSPath = path_1.default.resolve(process.env.UNI_INPUT_DIR, uni_cli_shared_1.PAGES_JSON_UTS);
  14. return {
  15. name: 'uni:app-pages',
  16. apply: 'build',
  17. resolveId(id) {
  18. if ((0, utils_1.isPages)(id)) {
  19. return pagesJsonUTSPath;
  20. }
  21. },
  22. load(id) {
  23. if ((0, utils_1.isPages)(id)) {
  24. return fs_extra_1.default.readFileSync(pagesJsonPath, 'utf8');
  25. }
  26. },
  27. transform(code, id) {
  28. if ((0, utils_1.isPages)(id)) {
  29. this.addWatchFile(path_1.default.resolve(process.env.UNI_INPUT_DIR, 'pages.json'));
  30. const pagesJson = (0, uni_cli_shared_1.normalizeUniAppXAppPagesJson)(code);
  31. this.emitFile({
  32. fileName: uni_cli_shared_1.APP_CONFIG,
  33. type: 'asset',
  34. source: (0, uni_cli_shared_1.normalizeUniAppXAppConfig)(pagesJson, (0, uni_cli_shared_1.parseManifestJsonOnce)(process.env.UNI_INPUT_DIR)),
  35. });
  36. return {
  37. code: (0, uni_cli_shared_1.normalizeAppPagesJson)(pagesJson),
  38. map: null,
  39. };
  40. }
  41. },
  42. };
  43. }
  44. exports.uniAppPagesPlugin = uniAppPagesPlugin;