Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tinkoff/babel-plugin-lodash

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tinkoff/babel-plugin-lodash

Transform lodash imports to include into bundle only imported functions

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

@tinkoff/babel-plugin-lodash

This plugin transforms lodash imports to include into bundle only imported functions.

Installation

npm install --save-dev @tinkoff/babel-plugin-lodash
yarn add --dev @tinkoff/babel-plugin-lodash

Example

In

import _ from "lodash";
import { add } from "lodash/fp";
import { slice } from "lodash-es";

const addOne = add(1);
_.map([1, 2, 3], addOne);
slice([1, 2, 3], 2);

Out

import _add from "lodash/fp/add";
import _map from "lodash/map";
import _slice from "lodash-es/slice";

const addOne = _add(1);
_map([1, 2, 3], addOne);
_slice([1, 2, 3], 2);

Usage

.babelrc

{
  "plugins": ["@tinkoff/babel-plugin-lodash"]
}

Via CLI

$ babel --plugins @tinkoff/babel-plugin-lodash script.js

Via Node.js API

require("@babel/core").transformSync(code, {
  plugins: ["@tinkoff/babel-plugin-lodash"],
});

Options

ensureModuleExists

boolean, defaults to false.

When this option is enabled, plugin tries to resolve path to imported lodash module using require.resolve(). If the module can not be found, an error is thrown. Usually such check is done out of box by bundler (e.g. webpack) or typescript. Enabling this option may lead to decreasing performance.

In

import _ from "lodash";

_.slice([1, 2], 1);
_.unknownFunc();

Out

import _slice from "lodash/slice"; // OK
import _unknownFunc from "lodash/unknownFunc"; // ERROR

_slice([1, 2], 1);
_unknownFunc();

Limitations

  • Supported lodash packages: lodash, lodash/fp, lodash-es
  • You must use ES6 imports to load Lodash
  • Babel < 7 & Node.js < 16 aren’t supported
  • Chain sequences aren’t supported. See this blog post for alternatives.
  • Modularized method packages aren’t supported

Keywords

FAQs

Package last updated on 19 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc