UNPKG

@wjunt/webpack-config

Version:

Presets of webpack config

80 lines (79 loc) 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EXTERNALS = { 'axios': 'axios', 'js-cookie': 'Cookies', 'intersection-observer': 'IntersectionObserver', '@wjunt/f': 'F', '@wjunt/md5': 'F', '@wjunt/uuid': ['F', 'uuid'], '@wjunt/dwp': ['F', 'dwp'], '@wjunt/dce': ['F', 'dce'], '@wjunt/url': ['F', 'url'], '@wjunt/image': ['F', 'image'], '@wjunt/logger': ['F', 'logger'], '@wjunt/tracker': ['F', 'tracker'], }; function getExternals(type = 'var') { if (type === 'commonjs' || type === 'commonjs2') { return Object.keys(exports.EXTERNALS); } return Object.keys(exports.EXTERNALS).reduce((externals, name) => { externals[name] = getExternalByName(name, type); return externals; }, {}); } exports.getExternals = getExternals; function getExternalByName(name, type) { const config = exports.EXTERNALS[name]; switch (type) { case 'umd': return { root: config, commonjs: name, commonjs2: name, }; case 'commonjs': case 'commonjs2': return name; case 'amd': return ''; case 'var': case 'this': default: return config; } } function mergeExternals(...args) { const object = {}; const array = []; for (const externals of args) { if (!externals) { continue; } if (Array.isArray(externals)) { for (const element of externals) { addElement(element); } } else { addElement(externals); } } if (array.length > 0) { if (Object.keys(object).length === 0) { return array; } return [object, ...array]; } return object; function addElement(element) { if (typeof element === 'string' || typeof element === 'function' || element instanceof RegExp) { array.push(element); } else { Object.assign(object, element); } } } exports.mergeExternals = mergeExternals;