更新
This commit is contained in:
+77
@@ -0,0 +1,77 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.uniEasycomPlugin = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const shared_1 = require("@vue/shared");
|
||||
const pluginutils_1 = require("@rollup/pluginutils");
|
||||
const url_1 = require("../utils/url");
|
||||
const constants_1 = require("../../constants");
|
||||
const easycom_1 = require("../../easycom");
|
||||
const transformUTSComponent_1 = require("../../vue/transforms/transformUTSComponent");
|
||||
const uts_1 = require("../../uts");
|
||||
function uniEasycomPlugin(options) {
|
||||
const filter = (0, pluginutils_1.createFilter)(options.include, options.exclude);
|
||||
return {
|
||||
name: 'uni:app-easycom',
|
||||
transform(code, id) {
|
||||
if (!filter(id)) {
|
||||
return;
|
||||
}
|
||||
const { filename } = (0, url_1.parseVueRequest)(id);
|
||||
if (!constants_1.EXTNAME_VUE_TEMPLATE.includes(path_1.default.extname(filename))) {
|
||||
return;
|
||||
}
|
||||
// 替换 UTS custom element import placeholder
|
||||
// 目前主要是iOS和harmony,Android不需要
|
||||
const hasUTSCustomElementImport = code.includes(transformUTSComponent_1.UTS_CUSTOM_ELEMENT_IMPORT_PLACEHOLDER);
|
||||
if (hasUTSCustomElementImport) {
|
||||
code = code.replace(new RegExp(`${transformUTSComponent_1.UTS_CUSTOM_ELEMENT_IMPORT_PLACEHOLDER} from `, 'g'), '');
|
||||
}
|
||||
if (!code.includes('_resolveComponent')) {
|
||||
if (hasUTSCustomElementImport) {
|
||||
return {
|
||||
code,
|
||||
map: {
|
||||
mappings: '',
|
||||
},
|
||||
};
|
||||
}
|
||||
return;
|
||||
}
|
||||
let i = 0;
|
||||
const importDeclarations = [];
|
||||
code = code.replace(/_resolveComponent\("(.+?)"(, true)?\)/g, (str, name) => {
|
||||
if (name && !name.startsWith('_')) {
|
||||
const source = (0, easycom_1.matchEasycom)(name);
|
||||
if (source) {
|
||||
// 处理easycom组件优先级
|
||||
return (0, easycom_1.genResolveEasycomCode)(importDeclarations, str, (0, easycom_1.addImportDeclaration)(importDeclarations, `__easycom_${i++}`, source, source.includes('uts-proxy')
|
||||
? (0, shared_1.capitalize)((0, shared_1.camelize)(name)) + 'Component'
|
||||
: source.includes('uni_helpers')
|
||||
? (0, shared_1.capitalize)((0, shared_1.camelize)(name))
|
||||
: ''));
|
||||
}
|
||||
else {
|
||||
const utsCustomElement = (0, uts_1.getUTSCustomElement)(name);
|
||||
if (utsCustomElement) {
|
||||
(0, easycom_1.addImportDeclaration)(importDeclarations, '', utsCustomElement.source, '');
|
||||
return `'${name}'`;
|
||||
}
|
||||
}
|
||||
}
|
||||
return str;
|
||||
});
|
||||
if (importDeclarations.length) {
|
||||
code = importDeclarations.join('') + code;
|
||||
}
|
||||
return {
|
||||
code,
|
||||
map: null,
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
exports.uniEasycomPlugin = uniEasycomPlugin;
|
||||
Reference in New Issue
Block a user