resolveId.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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.uniResolveIdPlugin = void 0;
  7. const path_1 = __importDefault(require("path"));
  8. const debug_1 = __importDefault(require("debug"));
  9. const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
  10. const utils_1 = require("../utils");
  11. const debugResolve = (0, debug_1.default)('uni:resolve');
  12. function uniResolveIdPlugin() {
  13. const resolveCache = {};
  14. return {
  15. name: 'uni:h5-resolve-id',
  16. enforce: 'pre',
  17. config() {
  18. resolveCache[utils_1.ownerModuleName] = (0, uni_cli_shared_1.resolveBuiltIn)(path_1.default.join(utils_1.ownerModuleName, (process.env.UNI_APP_X === 'true' ? 'dist-x' : 'dist') +
  19. '/uni-h5.es.js'));
  20. resolveCache['@dcloudio/uni-h5-vue'] = (0, uni_cli_shared_1.resolveBuiltIn)(path_1.default.join('@dcloudio/uni-h5-vue', (process.env.UNI_APP_X === 'true' ? 'dist-x' : 'dist') +
  21. `/vue.runtime.${process.env.VITEST ? 'cjs' : 'esm'}.js`));
  22. },
  23. resolveId(id) {
  24. if (id === 'vue') {
  25. id = '@dcloudio/uni-h5-vue';
  26. }
  27. const cache = resolveCache[id];
  28. if (cache) {
  29. debugResolve('cache', id, cache);
  30. return cache;
  31. }
  32. if (id.startsWith('@dcloudio/uni-h5/style')) {
  33. return (resolveCache[id] = (0, uni_cli_shared_1.resolveBuiltIn)(id));
  34. }
  35. if (id.startsWith('@dcloudio/uni-components/style')) {
  36. return (resolveCache[id] = (0, uni_cli_shared_1.resolveBuiltIn)(id));
  37. }
  38. },
  39. };
  40. }
  41. exports.uniResolveIdPlugin = uniResolveIdPlugin;