UNPKG

ptool

Version:

vue项目开发通用工具类封装

36 lines (35 loc) 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * @FileName vueComponentRegister.ts * @Author Mad Dragon <395548460@qq.com> * @Version V 0.0.1 * @Date 2021/8/13 15:56 * @Title * @Desc **/ // @ts-ignore const requireComponent = require.context('../components/', true, /\.vue$/); const getComponentName = (config, fileName) => { var _a, _b; const names = fileName.split('/'); const name = names[names.length - 1].split('.')[0]; return ((_b = (_a = config === null || config === void 0 ? void 0 : config.default) === null || _a === void 0 ? void 0 : _a.extendOptions) === null || _b === void 0 ? void 0 : _b.name) || name || config; }; const install = (Vue) => { if (install.installed) return; install.installed = true; requireComponent.keys().forEach((fileName) => { const config = requireComponent(fileName); const name = getComponentName(config, fileName); Vue.component(name, config.default || config); }); }; // 判断是否是直接引入文件,如果是,就不用调用 Vue.use() if (typeof window !== 'undefined' && window.Vue) { install(window.Vue); } exports.default = { install };