Rewrite module/package require calls to local files in browserify
MIT License
Pkgify is a browserify transform that allows you to rewrite module/package-style require
calls to local files. It is built using the browserify-transform-tools.
Aliasify is designed for mapping individual files to new names. Remapify actually uses aliasify internally for it's mapping process which means it has to generate a list of all possible files that might be mapped from the source directory, and then compare them when processing files. This gives remapify less control since it isn't doing the transform itself.
Say, for example, your project has the following tree structure:
myproject
- /app
- /views
- /home
- index.js
- /about
- index.js
- /models
- cars.js
- log.js
Normally, if you wanted to access log.js
and models/cars.js
from either of the two view files, you would have to do it like so:
var log = require("../../log");
var Cars = require("../../models/cars");
With pkgify, however, you can save yourself time and clean up your code so it looks like this:
var log = require("log");
var Cars = require("models/cars");
npm install --save-dev pkgify
Usage is identical to any other browserify-transform-tools
transforms:
Directly in package.json:
{
"pkgify": {
"packages": {
"views": "./app/views",
"log": "./app/log.js"
}
}
}
or using referencing a separate JS file in package.json:
{
"pkgify": "./pkgifyConfig.js"
}
var pkgify = require("pkgify");
b.transform(pkgify, {
packages: {
views: "./app/views",
log: "./app/log.js"
},
relativeTo: __dirname
});
packages
relativeTo
option and can reference either a file or directory. If a file is specified it's extension must be included.relativeTo
__dirname
.appliesTo
make bootstrap
make test
:lipstick:
when improving the format/structure of the code:racehorse:
when improving performance:non-potable_water:
when plugging memory leaks:memo:
when writing docs:penguin:
when fixing something on Linux:apple:
when fixing something on Mac OS:checkered_flag:
when fixing something on Windows:bug:
when fixing a bug:fire:
when removing code or files:green_heart:
when fixing the CI build:white_check_mark:
when adding tests:lock:
when dealing with security:arrow_up:
when upgrading dependencies:arrow_down:
when downgrading dependencies(From atom)