Skip to content

This plugin is for esbuild, similar to how babel-plugin-lodash works for babel.

License

Notifications You must be signed in to change notification settings

josteph/esbuild-plugin-lodash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ca5f25b · May 22, 2022

History

24 Commits
Oct 6, 2021
Oct 1, 2021
May 16, 2021
Mar 6, 2021
May 22, 2022
Mar 6, 2021
Oct 1, 2021
May 22, 2022
May 16, 2021
May 22, 2022
May 22, 2022

Repository files navigation

esbuild-plugin-lodash

npm

This plugin is for esbuild, similar to how babel-plugin-lodash works for babel.

Thoughts

The non-es lodash package is not tree-shakeable, this plugin is only for direct import workaround.

For better coding practices, you can use instead lodash-es directly or strictly import the required lodash function manually.

Installation

npm install --save-dev esbuild-plugin-lodash

Usage

Define plugin in the plugins section of esbuild config like this:

const esbuild = require('esbuild');
const lodashTransformer = require('esbuild-plugin-lodash');

esbuild.build({
  // ...
  plugins: [
    lodashTransformer(),
  ],
})

Result

Having this input file:

import { get, isEmpty }  from 'lodash';

const something = {};

get(something);
isEmpty(something);

It will output this following file content:

import get  from 'lodash/get';
import isEmpty  from 'lodash/isEmpty';

const something = {};

get(something);
isEmpty(something);

Options

You can specify your own filter as per according to esbuild docs here.

You can specify outLodashPackage which by default is lodash. An example of this would be specifying calls to be rewritten to use lodash-es.