nutui-taro-upgrade
Version:
@nutui/nutui-taro 对京东风格组件库的taro4 版本支持
27 lines (26 loc) • 858 B
JavaScript
const nutFunctions = ["showToast", "showNotify", "showDialog", "showImagePreview"];
function getNutResolved(name, options) {
const { taro = false, autoImport = false } = options;
const packageName = taro ? "nutui-taro-upgrade" : "@nutui/nutui";
const componentName = autoImport ? name.slice(4) : name;
const style = `${packageName}/dist/packages/${componentName.toLowerCase()}/style`;
return {
name,
from: packageName,
sideEffects: style
};
}
function NutUIResolver(options = {}) {
return {
type: "component",
resolve: (name) => {
const { autoImport = false } = options;
if (autoImport && nutFunctions.includes(name))
return getNutResolved(name, options);
if (name.startsWith("Nut"))
return getNutResolved(name.slice(3), options);
}
};
}
module.exports = NutUIResolver;
;