Socket
Book a DemoInstallSign in
Socket

lodash-ts-imports-loader

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lodash-ts-imports-loader

Transpiles ES6 lodash imports into typescript imports to help with tree-shaking

latest
Source
npmnpm
Version
1.2.0
Version published
Weekly downloads
5
-28.57%
Maintainers
1
Weekly downloads
 
Created
Source

Jump to

  • Overview
  • Usage
  • Installation
  • Links
  • License

Overview

[jump to TOC]

A webpack preloader which transpiles ES6 lodash imports into typescript imports to help with tree-shaking.

Basically transpiles from ES6 syntax:

import { debounce } from 'lodash';

into typescript syntax:

import debounce = require('lodash/debounce');

before the source code is being taken through the typescript compiler.

This way webpack 2 will be able to only include the code that's being actually used.

Installation

[jump to TOC]

  • Install the package:
$ npm install lodash-ts-imports-loader --save-dev

Usage

[jump to TOC]

In your webpack.config.js add the lodash-ts-imports-loader preloader:

// ...
module: {
    rules: [
        {
            test: /\.ts$/,
            loader: 'lodash-ts-imports-loader',
            exclude: /node_modules/,
            enforce: "pre"
        },
        // ...
    ],
    // ...
}
// ...

Now somewhere in your main.ts typescript file add an ES6 import for lodash:

import { debounce } from 'lodash';
// make sure you have this line as well otherwise you're not using the import member
// and the lodash code will not be included in the bundle
console.log(debounce); 

run webpack bundling and check your bundle size.

Update the code to:

import { debounce, zip } from 'lodash';
// make sure you have this lines as well otherwise you're not using the import members
// and the lodash code will not be included in the bundle
console.log(debounce); 
console.log(zip); 

run webpack bundling and check your bundle size.
This time the bundle size should be larger.

[jump to TOC]

NPM:
https://www.npmjs.com/package/lodash-ts-imports-loader
GITHUB:
https://github.com/efidiles/lodash-ts-imports-loader.git

Author

[jump to TOC]

Eduard Fidiles

License

[jump to TOC]
Released under the MIT license.

Copyright © 2016, Eduard Fidiles

Keywords

lodash

FAQs

Package last updated on 10 Jan 2018

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.