https://github.com/thlorenz/browserify-swap
A transform that swaps out modules according to a config in your package.json selected via an environment variable.
https://github.com/thlorenz/browserify-swap
Last synced: 2 months ago
JSON representation
A transform that swaps out modules according to a config in your package.json selected via an environment variable.
- Host: GitHub
- URL: https://github.com/thlorenz/browserify-swap
- Owner: thlorenz
- License: mit
- Created: 2013-12-19T20:26:16.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-12-21T12:21:08.000Z (over 9 years ago)
- Last Synced: 2025-04-16T03:21:36.156Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 234 KB
- Stars: 31
- Watchers: 2
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# browserify-swap [](http://travis-ci.org/thlorenz/browserify-swap)
**swap/swäp/** - *an act of exchanging one thing for another*
A transform that swaps out modules according to a config in your `package.json` selected via an environment variable.
#### package.json
```json
{
"browserify": {
"transform": [ "browserify-swap" ]
},
"browserify-swap": {
"@packages": [ "hyperwatch" ],
"dev": {
".*node_modules\/hyperwatch\/\\S+\\.js$": "./swap/some-hyperwatch-swap.js",
"util.js$": "myutil"
},
"test": {
"util.js$": "test-util"
}
}
}
```- each file matcher (i.e. `'util.js$'`) is a regular expression
- in order to swap files of dependencies the `browserify-swap` transform needs to be injected into its package,
therefore indicate those packages via the `@packages` array```sh
BROWSERIFYSWAP_ENV='dev' browserify . -o bundle.js
```## Installation
npm install browserify-swap
## API
browserifySwap(file) → {TransformStream}Looks up browserify_swap configuratios specified for the given file in the environment specified via
BROWSERIFYSWAP_ENV
.If found the file content is replaced with a require statement to the file to swap in for the original.
Otherwise the file's content is just piped through.Parameters:
Name
Type
Description
file
String
full path to file being transformed
Returns:
transform stream into which
browserify
will pipe the original content of the file
Type
TransformStream*generated with [docme](https://github.com/thlorenz/docme)*
## License
MIT