require-swapper
Swap CommonJS require call to custom function call.
Last updated 2 years ago by stomita .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install require-swapper 
SYNC missed versions from official npm registry.

browserify-require-swapper

Build Status

Browserify v2 transform to swap CommonJS require call to custom function call

Installation

npm install require-swapper browserify

Usage

Require-swapper swaps all CommonJS require() function calls in your code to specified custom function, or for certain module which matches given target module list.

Example

Suppose you have following index.js and swapping require function to myrequire() for module aaa,

var aaa = require('aaa')
  , bbb = require('./dir1/bbb')
  , ccc = require('./dir2/ccc')

module.exports = function() {
  aaa(bbb, ccc);
}

It will output the folowing content to downstream.

var aaa = myrequire('aaa')
  , bbb = require('./dir1/bbb')
  , ccc = require('./dir2/ccc')

module.exports = function() {
  aaa(bbb, ccc);
}

As the loading function for module aaa become swapped, browserify worker will not resolve and bundle the module aaa statically. It is anticipated that your custom loader function myrequire would resolve it.

Combining browserify CLI, you can use it like following:

browserify index.js -t [ require-swapper --fn 'myrequire' --module 'aaa'  ] > bundle.js

Options

options.fn

Specify your custom function name to swap require() call.

options.modules

A target module list or glob pattern to swap require(). If the option is not specified, all require() call will be replaced.

Current Tags

  • 0.1.7                                ...           latest (2 years ago)

8 Versions

  • 0.1.7                                ...           2 years ago
  • 0.1.6                                ...           4 years ago
  • 0.1.5                                ...           5 years ago
  • 0.1.4                                ...           5 years ago
  • 0.1.3                                ...           5 years ago
  • 0.1.2                                ...           6 years ago
  • 0.1.1                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 8
Last Day 0
Last Week 8
Last Month 0
Dependencies (5)
Dev Dependencies (5)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |