Last active
October 1, 2025 14:51
-
-
Save denisx/a06fc2b518ec152d2ef631674ac87b30 to your computer and use it in GitHub Desktop.
rsbuild: lodash transpiling / aliasing / mirgation to es-toolkit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // tested version | |
| lodash: 4.17 | |
| es-toolkit: 1.39 | |
| @rsbuild/core: 1.5 | |
| // for lodash.pullall -> lodash/pullAll | |
| const lodashAllNames = [ | |
| 'add', | |
| 'after', | |
| 'ary', | |
| 'assign', | |
| 'assignIn', | |
| 'assignInWith', | |
| 'assignWith', | |
| 'at', | |
| 'attempt', | |
| 'before', | |
| 'bind', | |
| 'bindAll', | |
| 'bindKey', | |
| 'camelCase', | |
| 'capitalize', | |
| 'castArray', | |
| 'ceil', | |
| 'chain', | |
| 'chunk', | |
| 'clamp', | |
| 'clone', | |
| 'cloneDeep', | |
| 'cloneDeepWith', | |
| 'cloneWith', | |
| 'compact', | |
| 'concat', | |
| 'cond', | |
| 'conforms', | |
| 'conformsTo', | |
| 'constant', | |
| 'countBy', | |
| 'create', | |
| 'curry', | |
| 'curryRight', | |
| 'debounce', | |
| 'deburr', | |
| 'defaults', | |
| 'defaultsDeep', | |
| 'defaultTo', | |
| 'defer', | |
| 'delay', | |
| 'difference', | |
| 'differenceBy', | |
| 'differenceWith', | |
| 'divide', | |
| 'drop', | |
| 'dropRight', | |
| 'dropRightWhile', | |
| 'dropWhile', | |
| 'each', | |
| 'eachRight', | |
| 'endsWith', | |
| 'entries', | |
| 'entriesIn', | |
| 'eq', | |
| 'escape', | |
| 'escapeRegExp', | |
| 'every', | |
| 'extend', | |
| 'extendWith', | |
| 'fill', | |
| 'filter', | |
| 'find', | |
| 'findIndex', | |
| 'findKey', | |
| 'findLast', | |
| 'findLastIndex', | |
| 'findLastKey', | |
| 'first', | |
| 'flatMap', | |
| 'flatMapDeep', | |
| 'flatMapDepth', | |
| 'flatten', | |
| 'flattenDeep', | |
| 'flattenDepth', | |
| 'flip', | |
| 'floor', | |
| 'flow', | |
| 'flowRight', | |
| 'forEach', | |
| 'forEachRight', | |
| 'forIn', | |
| 'forInRight', | |
| 'forOwn', | |
| 'forOwnRight', | |
| 'fromPairs', | |
| 'functions', | |
| 'functionsIn', | |
| 'get', | |
| 'groupBy', | |
| 'gt', | |
| 'gte', | |
| 'has', | |
| 'hasIn', | |
| 'head', | |
| 'identity', | |
| 'includes', | |
| 'indexOf', | |
| 'initial', | |
| 'inRange', | |
| 'intersection', | |
| 'intersectionBy', | |
| 'intersectionWith', | |
| 'invert', | |
| 'invertBy', | |
| 'invoke', | |
| 'invokeMap', | |
| 'isArguments', | |
| 'isArray', | |
| 'isArrayBuffer', | |
| 'isArrayLike', | |
| 'isArrayLikeObject', | |
| 'isBoolean', | |
| 'isBuffer', | |
| 'isDate', | |
| 'isElement', | |
| 'isEmpty', | |
| 'isEqual', | |
| 'isEqualWith', | |
| 'isError', | |
| 'isFinite', | |
| 'isFunction', | |
| 'isInteger', | |
| 'isLength', | |
| 'isMap', | |
| 'isMatch', | |
| 'isMatchWith', | |
| 'isNaN', | |
| 'isNative', | |
| 'isNil', | |
| 'isNull', | |
| 'isNumber', | |
| 'isObject', | |
| 'isObjectLike', | |
| 'isPlainObject', | |
| 'isRegExp', | |
| 'isSafeInteger', | |
| 'isSet', | |
| 'isString', | |
| 'isSymbol', | |
| 'isTypedArray', | |
| 'isUndefined', | |
| 'isWeakMap', | |
| 'isWeakSet', | |
| 'iteratee', | |
| 'join', | |
| 'kebabCase', | |
| 'keyBy', | |
| 'keys', | |
| 'keysIn', | |
| 'last', | |
| 'lastIndexOf', | |
| 'lowerCase', | |
| 'lowerFirst', | |
| 'lt', | |
| 'lte', | |
| 'map', | |
| 'mapKeys', | |
| 'mapValues', | |
| 'matches', | |
| 'matchesProperty', | |
| 'max', | |
| 'maxBy', | |
| 'mean', | |
| 'meanBy', | |
| 'memoize', | |
| 'merge', | |
| 'mergeWith', | |
| 'method', | |
| 'methodOf', | |
| 'min', | |
| 'minBy', | |
| 'mixin', | |
| 'multiply', | |
| 'negate', | |
| 'noop', | |
| 'now', | |
| 'nth', | |
| 'nthArg', | |
| 'omit', | |
| 'omitBy', | |
| 'once', | |
| 'orderBy', | |
| 'over', | |
| 'overArgs', | |
| 'overEvery', | |
| 'overSome', | |
| 'pad', | |
| 'padEnd', | |
| 'padStart', | |
| 'parseInt', | |
| 'partial', | |
| 'partialRight', | |
| 'partition', | |
| 'pick', | |
| 'pickBy', | |
| 'property', | |
| 'propertyOf', | |
| 'pull', | |
| 'pullAll', | |
| 'pullAllBy', | |
| 'pullAllWith', | |
| 'pullAt', | |
| 'random', | |
| 'range', | |
| 'rangeRight', | |
| 'rearg', | |
| 'reduce', | |
| 'reduceRight', | |
| 'reject', | |
| 'remove', | |
| 'repeat', | |
| 'replace', | |
| 'rest', | |
| 'result', | |
| 'reverse', | |
| 'round', | |
| 'sample', | |
| 'sampleSize', | |
| 'set', | |
| 'setWith', | |
| 'shuffle', | |
| 'size', | |
| 'slice', | |
| 'snakeCase', | |
| 'some', | |
| 'sortBy', | |
| 'sortedIndex', | |
| 'sortedIndexBy', | |
| 'sortedIndexOf', | |
| 'sortedLastIndex', | |
| 'sortedLastIndexBy', | |
| 'sortedLastIndexOf', | |
| 'sortedUniq', | |
| 'sortedUniqBy', | |
| 'split', | |
| 'spread', | |
| 'startCase', | |
| 'startsWith', | |
| 'stubArray', | |
| 'stubFalse', | |
| 'stubObject', | |
| 'stubString', | |
| 'stubTrue', | |
| 'subtract', | |
| 'sum', | |
| 'sumBy', | |
| 'tail', | |
| 'take', | |
| 'takeRight', | |
| 'takeRightWhile', | |
| 'takeWhile', | |
| 'tap', | |
| 'template', | |
| 'templateSettings', | |
| 'throttle', | |
| 'thru', | |
| 'times', | |
| 'toArray', | |
| 'toFinite', | |
| 'toInteger', | |
| 'toLength', | |
| 'toLower', | |
| 'toNumber', | |
| 'toPairs', | |
| 'toPairsIn', | |
| 'toPath', | |
| 'toPlainObject', | |
| 'toSafeInteger', | |
| 'toString', | |
| 'toUpper', | |
| 'transform', | |
| 'trim', | |
| 'trimEnd', | |
| 'trimStart', | |
| 'truncate', | |
| 'unary', | |
| 'unescape', | |
| 'union', | |
| 'unionBy', | |
| 'unionWith', | |
| 'uniq', | |
| 'uniqBy', | |
| 'uniqueId', | |
| 'uniqWith', | |
| 'unset', | |
| 'unzip', | |
| 'unzipWith', | |
| 'update', | |
| 'updateWith', | |
| 'upperCase', | |
| 'upperFirst', | |
| 'values', | |
| 'valuesIn', | |
| 'without', | |
| 'words', | |
| 'wrap', | |
| 'xor', | |
| 'xorBy', | |
| 'xorWith', | |
| 'zip', | |
| 'zipObject', | |
| 'zipObjectDeep', | |
| 'zipWith'] | |
| const lodashDotImports = lodashAllNames.map(item => ({ | |
| [item.toLowerCase()]: item | |
| })); | |
| // lodash at es-toolkit | |
| const lodashWhiteList = new Set([ | |
| "chunk", | |
| "compact", | |
| "concat", | |
| "difference", | |
| "differenceBy", | |
| "differenceWith", | |
| "drop", | |
| "dropRight", | |
| "dropRightWhile", | |
| "dropWhile", | |
| "fill", | |
| "findIndex", | |
| "findLastIndex", | |
| "flatten", | |
| "flattenDeep", | |
| "flattenDepth", | |
| "fromPairs", | |
| "head", | |
| "indexOf", | |
| "initial", | |
| "intersection", | |
| "intersectionBy", | |
| "intersectionWith", | |
| "join", | |
| "last", | |
| "lastIndexOf", | |
| "nth", | |
| "pull", | |
| "pullAll", | |
| "pullAllBy", | |
| "pullAllWith", | |
| "pullAt", | |
| "remove", | |
| "reverse", | |
| "slice", | |
| "sortedIndex", | |
| "sortedIndexBy", | |
| "sortedIndexOf", | |
| "sortedLastIndex", | |
| "sortedLastIndexBy", | |
| "sortedLastIndexOf", | |
| "tail", | |
| "take", | |
| "takeRight", | |
| "takeRightWhile", | |
| "takeWhile", | |
| "union", | |
| "unionBy", | |
| "unionWith", | |
| "uniq", | |
| "uniqBy", | |
| "uniqWith", | |
| "unzip", | |
| "unzipWith", | |
| "without", | |
| "xor", | |
| "xorBy", | |
| "xorWith", | |
| "zip", | |
| "zipObject", | |
| "zipObjectDeep", | |
| "zipWith", | |
| "countBy", | |
| "every", | |
| "filter", | |
| "find", | |
| "findLast", | |
| "flatMap", | |
| "flatMapDeep", | |
| "flatMapDepth", | |
| "forEach", | |
| "forEachRight", | |
| "groupBy", | |
| "includes", | |
| "invokeMap", | |
| "keyBy", | |
| "map", | |
| "orderBy", | |
| "partition", | |
| "reduce", | |
| "reduceRight", | |
| "reject", | |
| "sample", | |
| "sampleSize", | |
| "shuffle", | |
| "size", | |
| "some", | |
| "sortBy", | |
| "now", | |
| "after", | |
| "ary", | |
| "before", | |
| "bind", | |
| "bindKey", | |
| "curry", | |
| "curryRight", | |
| "debounce", | |
| "defer", | |
| "delay", | |
| "flip", | |
| "memoize", | |
| "negate", | |
| "once", | |
| "overArgs", | |
| "partial", | |
| "partialRight", | |
| "rearg", | |
| "rest", | |
| "spread", | |
| "throttle", | |
| "unary", | |
| "wrap", | |
| "castArray", | |
| "clone", | |
| "cloneDeep", | |
| "cloneDeepWith", | |
| "cloneWith", | |
| "conformsTo", | |
| "eq", | |
| "gt", | |
| "gte", | |
| "isArguments", | |
| "isArray", | |
| "isArrayBuffer", | |
| "isArrayLike", | |
| "isArrayLikeObject", | |
| "isBoolean", | |
| "isBuffer", | |
| "isDate", | |
| "isElement", | |
| "isEmpty", | |
| "isEqual", | |
| "isEqualWith", | |
| "isError", | |
| "isFinite", | |
| "isFunction", | |
| "isInteger", | |
| "isLength", | |
| "isMap", | |
| "isMatch", | |
| "isMatchWith", | |
| "isNaN", | |
| "isNative", | |
| "isNil", | |
| "isNull", | |
| "isNumber", | |
| "isObject", | |
| "isObjectLike", | |
| "isPlainObject", | |
| "isRegExp", | |
| "isSafeInteger", | |
| "isSet", | |
| "isString", | |
| "isSymbol", | |
| "isTypedArray", | |
| "isUndefined", | |
| "isWeakMap", | |
| "isWeakSet", | |
| "lt", | |
| "lte", | |
| "toArray", | |
| "toFinite", | |
| "toInteger", | |
| "toLength", | |
| "toNumber", | |
| "toPlainObject", | |
| "toSafeInteger", | |
| "toString", | |
| "add", | |
| "ceil", | |
| "divide", | |
| "floor", | |
| "max", | |
| "maxBy", | |
| "mean", | |
| "meanBy", | |
| "min", | |
| "minBy", | |
| "multiply", | |
| "round", | |
| "subtract", | |
| "sum", | |
| "sumBy", | |
| "clamp", | |
| "inRange", | |
| "random", | |
| "assign", | |
| "assignIn", | |
| "assignInWith", | |
| "assignWith", | |
| "at", | |
| "create", | |
| "defaults", | |
| "defaultsDeep", | |
| "findKey", | |
| "findLastKey", | |
| "forIn", | |
| "forInRight", | |
| "forOwn", | |
| "forOwnRight", | |
| "functions", | |
| "functionsIn", | |
| "get", | |
| "has", | |
| "hasIn", | |
| "invert", | |
| "invertBy", | |
| "invoke", | |
| "keys", | |
| "keysIn", | |
| "mapKeys", | |
| "mapValues", | |
| "merge", | |
| "mergeWith", | |
| "omit", | |
| "omitBy", | |
| "pick", | |
| "pickBy", | |
| "result", | |
| "set", | |
| "setWith", | |
| "toPairs", | |
| "toPairsIn", | |
| "transform", | |
| "unset", | |
| "update", | |
| "updateWith", | |
| "values", | |
| "valuesIn", | |
| "camelCase", | |
| "capitalize", | |
| "deburr", | |
| "endsWith", | |
| "escape", | |
| "escapeRegExp", | |
| "kebabCase", | |
| "lowerCase", | |
| "lowerFirst", | |
| "pad", | |
| "padEnd", | |
| "padStart", | |
| "parseInt", | |
| "repeat", | |
| "replace", | |
| "snakeCase", | |
| "split", | |
| "startCase", | |
| "startsWith", | |
| "template", | |
| "toLower", | |
| "toUpper", | |
| "trim", | |
| "trimEnd", | |
| "trimStart", | |
| "truncate", | |
| "unescape", | |
| "upperCase", | |
| "upperFirst", | |
| "words", | |
| "attempt", | |
| "bindAll", | |
| "cond", | |
| "conforms", | |
| "constant", | |
| "defaultTo", | |
| "flow", | |
| "flowRight", | |
| "identity", | |
| "iteratee", | |
| "matches", | |
| "matchesProperty", | |
| "method", | |
| "methodOf", | |
| "noop", | |
| "nthArg", | |
| "over", | |
| "overEvery", | |
| "overSome", | |
| "property", | |
| "propertyOf", | |
| "range", | |
| "rangeRight", | |
| "stubArray", | |
| "stubFalse", | |
| "stubObject", | |
| "stubString", | |
| "stubTrue", | |
| "times", | |
| "toPath", | |
| "uniqueId" | |
| ] | |
| ); | |
| rsconfig > tools > rspack > plugins | |
| [ | |
| // lodash -> lodash-es | |
| new NormalModuleReplacementPlugin(/^lodash[./](\w+)$/, (resource) => { | |
| const match = resource.request.match(/^lodash[./](\w+)$/); | |
| if (match) { | |
| const originalName = match[1]; | |
| const mappedName = lodashDotImports[originalName] || originalName; | |
| resource.request = `lodash-es/${mappedName}`; | |
| } | |
| }), | |
| // lodash > es-toolkit | |
| new NormalModuleReplacementPlugin(/^lodash-es\/(\w+)$/, (resource) => { | |
| const fn = resource.request.match(/^lodash-es\/(\w+)$/)[1]; | |
| if (lodashWhiteList.has(fn)) { | |
| resource.request = `es-toolkit/compat/${fn}`; | |
| } | |
| }), | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment