Skip to content

Browserify plugin that enforces that certain packages are not imported

Notifications You must be signed in to change notification settings

jharting/banify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

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\/.*/,
];

About

Browserify plugin that enforces that certain packages are not imported

Resources

Stars

Watchers

Forks

Packages

No packages published