Skip to content

Commit

Permalink
feat: replace lodash with webpack-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed Sep 3, 2024
1 parent 68d94b2 commit 9ee2cfc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"dependencies": {
"deep-for-each": "^3.0.0",
"lodash": "^4.17.21"
"webpack-merge": "^6.0.1"
},
"jest": {
"collectCoverageFrom": [
Expand Down
45 changes: 42 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 5 additions & 16 deletions src/options/default.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const mergeWith = require("lodash/mergeWith");
const { merge } = require("webpack-merge");

const gruntOptions = {
failOnError: (options) => {
Expand Down Expand Up @@ -39,13 +39,6 @@ const webpackDevServerOptions = {
},
};

// eslint-disable-next-line consistent-return
function mergeCustomize(a, b) {
if (Array.isArray(a) && Array.isArray(b)) {
return a.concat(b);
}
}

function mergeOptions(defaultOptions, options, targetOptions) {
if (Array.isArray(targetOptions) && Array.isArray(options)) {
if (targetOptions.length !== options.length) {
Expand All @@ -55,21 +48,17 @@ function mergeOptions(defaultOptions, options, targetOptions) {
);
}
return targetOptions.map((opt, index) =>
mergeWith({}, defaultOptions, options[index], opt, mergeCustomize),
merge(defaultOptions, options[index], opt),
);
}

if (Array.isArray(targetOptions)) {
return targetOptions.map((opt) =>
mergeWith({}, defaultOptions, options, opt, mergeCustomize),
);
return targetOptions.map((opt) => merge(defaultOptions, options, opt));
} else if (Array.isArray(options)) {
return options.map((opt) =>
mergeWith({}, defaultOptions, opt, targetOptions, mergeCustomize),
);
return options.map((opt) => merge(defaultOptions, opt, targetOptions));
}

return mergeWith({}, defaultOptions, options, targetOptions, mergeCustomize);
return merge(defaultOptions, options, targetOptions);
}

exports.gruntOptions = gruntOptions;
Expand Down

0 comments on commit 9ee2cfc

Please sign in to comment.