From 2caf5db9641d487e07439f96d2840b940800aff5 Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:41:07 +0300 Subject: [PATCH] fix: avoid importing all of lodash (#1864) --- index.js | 4 ++-- lib/loader.js | 4 ++-- spec/basic.spec.js | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 993bdfdb..f29b762d 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ const promisify = require("util").promisify; const vm = require("vm"); const fs = require("fs"); -const _ = require("lodash"); +const _uniq = require("lodash/uniq"); const path = require("path"); const { CachedChildCompilation } = require("./lib/cached-child-compiler"); @@ -987,7 +987,7 @@ class HtmlWebpackPlugin { * @private */ getAssetFiles(assets) { - const files = _.uniq( + const files = _uniq( Object.keys(assets) .filter((assetType) => assetType !== "chunks" && assets[assetType]) .reduce((files, assetType) => files.concat(assets[assetType]), []), diff --git a/lib/loader.js b/lib/loader.js index 8c385921..c9a69260 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -1,7 +1,7 @@ /* This loader renders the template with underscore if no other loader was found */ // @ts-nocheck "use strict"; -const _ = require("lodash"); +const _template = require("lodash/template"); module.exports = function (source) { // Get templating options @@ -34,7 +34,7 @@ module.exports = function (source) { // The following part renders the template with lodash as a minimalistic loader // - const template = _.template(source, { + const template = _template(source, { interpolate: /<%=([\s\S]+?)%>/g, variable: "data", ...options, diff --git a/spec/basic.spec.js b/spec/basic.spec.js index 6a415ea9..14cbef6b 100644 --- a/spec/basic.spec.js +++ b/spec/basic.spec.js @@ -9,7 +9,7 @@ const path = require("path"); const fs = require("fs"); const webpack = require("webpack"); const rimraf = require("rimraf"); -const _ = require("lodash"); +const _extend = require("lodash/extend"); const MiniCssExtractPlugin = require("mini-css-extract-plugin"); const webpackMajorVersion = Number( require("webpack/package.json").version.split(".")[0], @@ -2167,7 +2167,7 @@ describe("HtmlWebpackPlugin", () => { compilation, ).beforeEmit.tapAsync("HtmlWebpackPluginTest", (object, callback) => { eventFiredForFirstPlugin = true; - const result = _.extend(object, { + const result = _extend(object, { html: object.html + "Injected by first plugin", }); callback(null, result); @@ -2224,7 +2224,7 @@ describe("HtmlWebpackPlugin", () => { compilation, ).beforeEmit.tapAsync("HtmlWebpackPluginTest", (object, callback) => { eventFiredForFirstPlugin = true; - const result = _.extend(object, { + const result = _extend(object, { html: object.html + "Injected by first plugin", }); callback(null, result); @@ -2239,7 +2239,7 @@ describe("HtmlWebpackPlugin", () => { compilation, ).beforeEmit.tapAsync("HtmlWebpackPluginTest", (object, callback) => { eventFiredForSecondPlugin = true; - const result = _.extend(object, { + const result = _extend(object, { html: object.html + " Injected by second plugin", }); callback(null, result);