0.0.2 • Published 7 years ago

banify v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

banify

Browserify plugin that bans certain packages from being imported.

Normally you should do this at the package manager level (e.g. using dependency-ban). However, this plugin is useful in scenarios when you want to use a dependency but want to ensure that only parts of it are ever included in the browserify build.

This plugin is inspired by Apache Maven Enforcer Plugin.

Example

Let's say you are using lodash and only cherry-picking certain functions to keep the resulting bundle small.

var find = require('lodash/collection/find');

You want to enforce that no one accidentally requires all of lodash (e.g. by require('lodash')) because that would invalidate the effort. You can use banify to do that:

var banify = require('banify');
var BLACKLIST = [
    'lodash',
];

gulp.src(['./index.js'])
    .pipe(bro({
        plugin: [banify(BLACKLIST)]
    }))

The plugin fails the build if require('lodash') or is found anywhere in the codebase. Other imports (e.g. require('lodash/collection/find')) will succeed.

Besides exact matches a blacklist can also contain regular expressions:

var BLACKLIST = [
    /lodash\/fp\/.*/,
];