uniConfig.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.parseEntryPagePath = exports.normalizeAppUniConfig = void 0;
  7. const path_1 = __importDefault(require("path"));
  8. const i18n_1 = require("../../../i18n");
  9. const manifest_1 = require("../../manifest");
  10. const manifest_2 = require("../manifest");
  11. const arguments_1 = require("../manifest/arguments");
  12. const splashscreen_1 = require("../manifest/splashscreen");
  13. const theme_1 = require("../../theme");
  14. function normalizeAppUniConfig(pagesJson, manifestJson) {
  15. const { autoclose, alwaysShowBeforeRender } = (0, splashscreen_1.getSplashscreen)(manifestJson);
  16. const platformConfig = (0, manifest_1.getPlatformManifestJsonOnce)();
  17. const config = {
  18. pages: [],
  19. globalStyle: pagesJson.globalStyle,
  20. nvue: {
  21. compiler: (0, manifest_2.getNVueCompiler)(manifestJson),
  22. styleCompiler: (0, manifest_2.getNVueStyleCompiler)(manifestJson),
  23. 'flex-direction': (0, manifest_2.getNVueFlexDirection)(manifestJson),
  24. },
  25. renderer: manifestJson['app-plus']?.renderer === 'native' ? 'native' : 'auto',
  26. appname: manifestJson.name || '',
  27. splashscreen: {
  28. alwaysShowBeforeRender,
  29. autoclose,
  30. },
  31. compilerVersion: process.env.UNI_COMPILER_VERSION,
  32. ...parseEntryPagePath(pagesJson),
  33. networkTimeout: (0, manifest_1.normalizeNetworkTimeout)(manifestJson.networkTimeout),
  34. tabBar: pagesJson.tabBar,
  35. fallbackLocale: manifestJson.fallbackLocale,
  36. locales: (0, i18n_1.initLocales)(path_1.default.join(process.env.UNI_INPUT_DIR, 'locale')),
  37. darkmode: platformConfig.darkmode || false,
  38. themeConfig: (0, theme_1.normalizeThemeConfigOnce)(platformConfig),
  39. };
  40. // TODO 待支持分包
  41. return JSON.stringify(config);
  42. }
  43. exports.normalizeAppUniConfig = normalizeAppUniConfig;
  44. function parseEntryPagePath(pagesJson) {
  45. const res = {
  46. entryPagePath: '',
  47. entryPageQuery: '',
  48. realEntryPagePath: '',
  49. };
  50. if (!pagesJson.pages.length) {
  51. return res;
  52. }
  53. res.entryPagePath = pagesJson.pages[0].path;
  54. const argsJsonStr = (0, arguments_1.parseArguments)(pagesJson);
  55. if (argsJsonStr) {
  56. try {
  57. const args = JSON.parse(argsJsonStr);
  58. const entryPagePath = args.path || args.pathName;
  59. const realEntryPagePath = res.entryPagePath;
  60. if (entryPagePath && realEntryPagePath !== entryPagePath) {
  61. res.entryPagePath = entryPagePath;
  62. res.entryPageQuery = args.query ? '?' + args.query : '';
  63. // non tabBar page
  64. if (!(pagesJson.tabBar?.list || []).find((page) => page.pagePath === entryPagePath)) {
  65. res.realEntryPagePath = realEntryPagePath;
  66. }
  67. }
  68. }
  69. catch (e) { }
  70. }
  71. return res;
  72. }
  73. exports.parseEntryPagePath = parseEntryPagePath;