GithubHelp home page GithubHelp logo

thlorenz / browserify-devdupe Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 1.0 168 KB

Dedupes packages included in a browserify bundle according to a given crite

License: MIT License

JavaScript 100.00%

browserify-devdupe's Introduction

browserify-devdupe build status

Dedupes packages included in a browserify bundle according to a given criteria.

Warning

Don't use this in production - hence the name - instead you should npm dedupe your package and run the normal browserify instead.

browserify-devdupe is solely in existance to solve one problem: npm dedupe does not work with linked sub modules.

So if you don't plan to use npm link or ln -s in your development process this is not for you and you can stop reading now. At the same token if you are sure that all libraries that need to be deduped have the same version you will also not need this since [email protected] or greater already dedupes modules with exact same file content.

What it does

While dynamic-dedupe solves dedupe breaking for server side modules as long as they have the exact same versions, browserify-devdupe does the same for modules bundled with browserify, except that it allows you to give a dedupe-criteria.

Therefore if you need all your dependencies to always pull in exactly one instance of a library i.e. backbone, you can use browserify-devdupe to redirect all modules depending on older versions to the latest common denominator.

var browserify = require('browserify')
  , devdupe = require('browserify-devdupe')
  , entry = require.resolve('../test/fixtures/');

devdupe(browserify(), 'patch')
  .require(entry, { entry: true })
  .bundle(function (err, src) { 
    console.log('\npatch\n');
    eval(src); 
  });

devdupe(browserify(), 'major')
  .require(entry, { entry: true })
  .bundle(function (err, src) { 
    console.log('\nmajor\n');
    eval(src); 
  });

devdupe(browserify(), 'any')
  .require(entry, { entry: true })
  .bundle(function (err, src) { 
    console.log('\nany\n');
    eval(src); 
  });


// Note: eval is evil except in some cases (like simple examples)

Output:

patch

loading common 0.1.0
loading common 0.1.5
loading common 0.2.0
loading common 1.0.0
depends-0.1.0 - common common-0.1.0
also-depends-0.1.0 - common common-0.1.0
depends-0.1.5 - common dep - common-0.1.5
depends-0.2.0 - common common-0.2.0
depends-1.0.0 - common common-1.0.0

major

loading common 0.2.0
loading common 1.0.0
depends-0.1.0 - common dep - common-0.1.5
also-depends-0.1.0 - common dep - common-0.1.5
depends-0.1.5 - common common-0.2.0
depends-0.2.0 - common common-0.2.0
depends-1.0.0 - common common-1.0.0

any

loading common 1.0.0
depends-0.1.0 - common common-1.0.0
also-depends-0.1.0 - common common-1.0.0
depends-0.1.5 - common common-1.0.0
depends-0.2.0 - common common-1.0.0
depends-1.0.0 - common common-1.0.0

Installation

npm install browserify-devdupe

API

###devdupe(browserifyInstance, criteria = 'minor')

/**
 * Adds deduping behavior based on the given criteria to the browserify instance.
 * 
 * @name exports
 * @function
 * @param bfy {Object} browserify instance (i.e. result of `browserify()`)
 * @param criteria {String} exact | patch | minor | major | any 
 * @return {Object} the browserify instance with added behavior
 */

criteria

  • exact versions have to be equal
  • patch major and minor and patch numbers have to be equal, alpha, beta suffixes may vary
  • minor major and minor numbers have to be equal, patch number may vary
  • major major number has to be equal, minor and patch numbers may vary
  • any versions are not considered

License

MIT

browserify-devdupe's People

Contributors

thlorenz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ahutchings

browserify-devdupe's Issues

Published?

Is this complete and published to NPM? I am unable to install it. It definitely would solve a big problem for me.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.