webpack-externalize-lodash
raw JSON → 1.0.1 verified Sat Apr 25 auth: no javascript
A utility function for webpack that externalizes lodash from your bundle, handling all common import patterns (lodash, lodash-es, lodash-specific submodules like lodash/get, lodash-es/get, lodash.get). Version 1.0.1, stable. Unlike simple externals config like { lodash: '_' }, this package uses webpack's externals function to cover edge cases where lodash is imported in multiple ways by different dependencies, preventing duplicate inclusion. Lightweight, no dependencies.
Common errors
error Cannot find module 'webpack-externalize-lodash' ↓
cause Package not installed or located in node_modules.
fix
Run 'npm install webpack-externalize-lodash' and ensure your webpack config file is in the project root.
error TypeError: externals[i] is not a function ↓
cause The externals array contains a string instead of the required function.
fix
Replace 'webpack-externalize-lodash' with require('webpack-externalize-lodash') in externals.
Warnings
gotcha The package only externalizes lodash; it does not include lodash in your bundle. You must ensure lodash is available as a global (e.g., via CDN or script tag) or included separately. ↓
fix Add a script tag for lodash in your HTML or use a different externals configuration.
gotcha Does not handle lodash/fp imports (e.g., import get from 'lodash/fp/get'). These will still be bundled unless handled separately. ↓
fix Extend externals function manually to cover lodash/fp paths or use a more comprehensive externalization library.
Install
npm install webpack-externalize-lodash yarn add webpack-externalize-lodash pnpm add webpack-externalize-lodash Imports
- default wrong
import externalizeLodash from 'webpack-externalize-lodash';correctconst externalizeLodash = require('webpack-externalize-lodash'); - default as function in externals array wrong
externals: [ 'webpack-externalize-lodash' ]correctexternals: [ require('webpack-externalize-lodash') ]
Quickstart
// webpack.config.js
const externalizeLodash = require('webpack-externalize-lodash');
module.exports = {
// ... other config
externals: [
// your other externals
externalizeLodash
]
};