78 lines
3.3 KiB
JavaScript
78 lines
3.3 KiB
JavaScript
"use strict";
|
||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||
};
|
||
Object.defineProperty(exports, "__esModule", { value: true });
|
||
exports.uniResolveIdPlugin = void 0;
|
||
const path_1 = __importDefault(require("path"));
|
||
// import debug from 'debug'
|
||
const fs_extra_1 = __importDefault(require("fs-extra"));
|
||
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
||
// const debugResolve = debug('uni:resolve-id')
|
||
let isPiniaVersion3 = false;
|
||
try {
|
||
isPiniaVersion3 =
|
||
Number(fs_extra_1.default
|
||
.readJSONSync(path_1.default.join((0, uni_cli_shared_1.resolveBuiltIn)('pinia/package.json')))
|
||
.version.split('.')[0]) >= 3;
|
||
}
|
||
catch (error) { }
|
||
const BUILT_IN_MODULES = {
|
||
'vue-router': 'dist/vue-router.esm-bundler.js',
|
||
vuex: 'dist/vuex.esm-bundler.js',
|
||
'vue-i18n': 'dist/vue-i18n.esm-bundler.js',
|
||
'@dcloudio/uni-app': 'dist/uni-app.es.js',
|
||
'@dcloudio/uni-cloud': 'dist/uni-cloud.es.js',
|
||
'@dcloudio/uni-i18n': 'dist/uni-i18n.es.js',
|
||
'@dcloudio/uni-shared': 'dist/uni-shared.es.js',
|
||
'@dcloudio/uni-stacktracey': 'dist/uni-stacktracey.es.js',
|
||
'@vue/shared': 'dist/shared.esm-bundler.js',
|
||
pinia: isPiniaVersion3 ? '' : 'dist/pinia.mjs',
|
||
};
|
||
function uniResolveIdPlugin(options) {
|
||
const resolveCache = {};
|
||
const isX = process.env.UNI_APP_X === 'true';
|
||
const useProjectPinia = isX && (0, uni_cli_shared_1.resolveProjectPinia)() !== undefined;
|
||
// 内部会先判断项目能否解析 vue-i18n,仅无法解析时才返回内置依赖别名。
|
||
const builtInDependencies = {
|
||
// 内部会先判断项目能否解析 pinia,仅无法解析时才返回内置依赖别名。
|
||
...(0, uni_cli_shared_1.resolvePiniaDependencies)(),
|
||
};
|
||
if (isX) {
|
||
BUILT_IN_MODULES['@dcloudio/uni-app'] = 'dist-x/uni-app.es.js';
|
||
BUILT_IN_MODULES['@dcloudio/uni-cloud'] = 'dist/uni-cloud-x.es.js';
|
||
}
|
||
return {
|
||
name: 'uni:resolve-id',
|
||
resolveId(id, importer) {
|
||
if (isX && process.env.UNI_UTS_PLATFORM.startsWith('mp-')) {
|
||
// TODO 优化此逻辑,目前unicloud-db等内置组件依赖UTSJSONObject时会自动引用tslib,此处逻辑防止内置组件引用插件内置tslib
|
||
if (id === 'tslib') {
|
||
return '\0tslib.js';
|
||
}
|
||
}
|
||
const cache = resolveCache[id];
|
||
if (cache) {
|
||
// debugResolve('cache', id, cache)
|
||
return cache;
|
||
}
|
||
if (isX && id === 'pinia') {
|
||
if (useProjectPinia) {
|
||
return;
|
||
}
|
||
return (resolveCache[id] = (0, uni_cli_shared_1.resolvePinia)());
|
||
}
|
||
if (builtInDependencies[id]) {
|
||
return (resolveCache[id] = builtInDependencies[id]);
|
||
}
|
||
if (BUILT_IN_MODULES[id]) {
|
||
return (resolveCache[id] = (0, uni_cli_shared_1.resolveBuiltIn)(path_1.default.join(id, BUILT_IN_MODULES[id])));
|
||
}
|
||
if (process.env.UNI_PLATFORM !== 'app') {
|
||
return (0, uni_cli_shared_1.resolveUTSModule)(id, importer ? path_1.default.dirname(importer) : process.env.UNI_INPUT_DIR);
|
||
}
|
||
},
|
||
};
|
||
}
|
||
exports.uniResolveIdPlugin = uniResolveIdPlugin;
|