All Projects → ckotzbauer → lodash-loader

ckotzbauer / lodash-loader

Licence: MIT license
Cherry-picks Lodash functions and require them explicitly to reduce the webpack bundle size.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to lodash-loader

Svg Url Loader
A webpack loader which loads SVG file as utf-8 encoded DataUrl string.
Stars: ✭ 217 (+1569.23%)
Mutual labels:  webpack-loader
gzip-loader
[DEPRECATED] gzip loader module for webpack
Stars: ✭ 15 (+15.38%)
Mutual labels:  webpack-loader
tooltip-generator
💫 A tool to generate CSS code for tooltips. Built with Vue.js and Tailwind CSS
Stars: ✭ 32 (+146.15%)
Mutual labels:  lodash
One Loader
Single-file components for React
Stars: ✭ 233 (+1692.31%)
Mutual labels:  webpack-loader
sizeof-loader
Webpack loader that works like url-loader (or file-loader) but with extracted information such as image dimensions and file-size.
Stars: ✭ 20 (+53.85%)
Mutual labels:  webpack-loader
image-minimizer-webpack-plugin
Webpack loader and plugin to compress images using imagemin
Stars: ✭ 180 (+1284.62%)
Mutual labels:  webpack-loader
String Replace Loader
Replace loader for Webpack
Stars: ✭ 205 (+1476.92%)
Mutual labels:  webpack-loader
angular-hmr-loader
🔥 Angular HMR Webpack Loader by @AngularClass
Stars: ✭ 32 (+146.15%)
Mutual labels:  webpack-loader
ljq eleme
vue2 +vue-router2 + es6 +webpack 高仿饿了么Web app商家详情核心模块
Stars: ✭ 22 (+69.23%)
Mutual labels:  lodash
webpack-demos
webpack小练习
Stars: ✭ 17 (+30.77%)
Mutual labels:  webpack-loader
Vue Template Loader
Vue.js 2.0 template loader for webpack
Stars: ✭ 253 (+1846.15%)
Mutual labels:  webpack-loader
lancet
A comprehensive, efficient, and reusable util function library of go.
Stars: ✭ 2,228 (+17038.46%)
Mutual labels:  lodash
vue-hot-reload-loader
Enable hot module replacement (HMR) on your Vue components
Stars: ✭ 20 (+53.85%)
Mutual labels:  webpack-loader
Frontmatter Markdown Loader
📝 Webpack Loader for: FrontMatter (.md) -> HTML + Attributes (+ React/Vue Component)
Stars: ✭ 228 (+1653.85%)
Mutual labels:  webpack-loader
fengari-loader
Webpack loader for fengari
Stars: ✭ 27 (+107.69%)
Mutual labels:  webpack-loader
Exports Loader
Exports Loader
Stars: ✭ 205 (+1476.92%)
Mutual labels:  webpack-loader
jsx-compress-loader
⚛️JSX optimisation loader to reduce size of React application
Stars: ✭ 40 (+207.69%)
Mutual labels:  webpack-loader
R.apex
Functional utility library for Apex
Stars: ✭ 80 (+515.38%)
Mutual labels:  lodash
css-raw-loader
🌁 CSS Raw loader module for Webpack
Stars: ✭ 13 (+0%)
Mutual labels:  webpack-loader
fast-cartesian
Fast cartesian product
Stars: ✭ 51 (+292.31%)
Mutual labels:  lodash

Lodash Loader

test node NPM

DEPRECATED: This project is not maintained anymore.

This Webpack loader cherry-picks Lodash functions and require them explicitly to reduce the webpack bundle size.

Installation

npm install lodash-loader

Usage

JavaScript source files

Add this to your webpack.config.js to apply the logic to your .js files.

const createLodashAliases = require('lodash-loader').createLodashAliases;

module.exports = {
  ...
  module: {
      rules: [
          { test: /\.js$/, loader: "babel-loader!lodash-loader" }
      ]
  },
  resolve: {
      alias: createLodashAliases()
  }
  ...
};

TypeScript source files

Add this to your webpack.config.js to apply the logic to your .ts files.

const createLodashAliases = require('lodash-loader').createLodashAliases;

module.exports = {
  ...
  module: {
      rules: [
          { test: /\.ts$/, loader: "ts-loader!lodash-loader" }
      ]
  },
  resolve: {
      alias: createLodashAliases()
  }
  ...
};

Note: This loader has to run before babel-loader or ts-loader.

Important notes

This loader changes your code to explicitly reference single lodash functions instead of import the whole lodash library.

Example:

import * as _ from "lodash";

export class Main {

    public myMethod() {
        _.each([], (e) => {
            console.log(e);
        });

        _.isArray({});

        _.filter([], { name: "joe" });
    }
}

This is modified to:

import * as _each from "lodash/each";
import * as _isArray from "lodash/isArray";
import * as _filter from "lodash/filter";

export class Main {

    public myMethod() {
        _each([], (e) => {
            console.log(e);
        });

        _isArray({});

        _filter([], { name: "joe" });
    }
}

This works only if you import the lodash library in your code. Do NOT use lodash from browsers window variable. The import has to be a valid ES2015 or TypeScript-Import:

import _ from "lodash";
import * as _ from "lodash";

Function chaining is NOT supported at the moment. The same applies to lodash/fp functions.

Configuration

You can configure a query parameter called importMode to decide the destination import format:

Parameter Mandatory Data type Possible values Default value
importMode False String legacy,es2015,es2015-default,commonjs legacy

Comparison

This are analysis of a webpack build from a medium-sized web-project. There were 11 different functions in use.

Analyse Library
underscore Underscore 1.8.3 (51,7k)
lodash-unoptimized Lodash 4.17.4 (full) (526,9k)
lodash-optimized Lodash 4.17.4 (optimized) (140,8k)

License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].