UNPKG

plugin-light

Version:

Webpack 相关插件、Loader、基础配置及 CLI 命令

80 lines (71 loc) 2.87 kB
'use strict'; function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } /** * 记录每个页面的动态组件 */ function autoPlaceLoader() { var _global; var source = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; if (process.env.VUE_APP_PLATFORM !== 'mp-weixin' && process.env.VUE_APP_PLATFORM !== 'mp-qq') { return source; } var reg = new RegExp(/(([a-zA-Z]+?)\(resolve\)(?:\s*?)\{(?:\n\s*)require\(\['(.*?)'\],(?:\s*?)resolve\);(?:\n\s*)\})+/, 'g'); var match = _toConsumableArray(source.matchAll(reg)); if (!(match !== null && match !== void 0 && match.length)) { return source; } var compList = match.map(function (item) { var name = item === null || item === void 0 ? void 0 : item[2]; var filePath = ''; if (item !== null && item !== void 0 && item[3]) { filePath = item[3]; if (filePath.startsWith('src/')) { filePath = filePath.replace('src/', '/'); } else if (filePath.startsWith('./')) { filePath = filePath.replace('./', '/'); } else if (filePath.startsWith('../../')) { filePath = filePath.replace('../../', '/'); } else if (filePath.startsWith('../')) { filePath = filePath.replace('../', '/'); } if (filePath.endsWith('.vue')) { filePath = filePath.replace('.vue', ''); } } return { name: name, filePath: filePath }; }); if (!((_global = global) !== null && _global !== void 0 && _global.placeholderMap)) { global.placeholderMap = new Map(); } // @ts-ignore global.placeholderMap.set(this.resourcePath.replace('.vue', ''), compList); return source; } module.exports = autoPlaceLoader;