Open glassresistor opened 9 years ago
+1 to this—I just spent an hour trying to figure out what was wrong in my configuration (where I was trying to aliasify underscore to lodash for use in a required Backbone), but it seems that aliasify, as with the browser field, doesn't affect anything within your node_modules directory. If this is the case, that should be added to the documentation.
To clarify, I'd have expected this to work:
demo.js:
module.exports = require( 'backbone' );
package.json:
{
"scripts": {
"test": "browserify demo.js | grep lodash"
},
"browserify": {
"transform": [ "aliasify" ]
},
"aliasify": {
"aliases": {
"underscore": "lodash"
}
},
"dependencies": {
"backbone": "^1.2.1",
"jquery": "^2.1.4",
"lodash": "^3.10.0"
},
"devDependencies": {
"aliasify": "^1.7.2",
"browserify": "^10.2.6"
}
}
npm test
will not output anything, meaning that lodash isn't being subbed in.
This is a restriction imposed on us by browserify. Browserify will never run transforms on modules.
You might try the new --global-transform
option in Browserify, though, and see if that does what you want.
@jwalton I just discovered the --global-transform
option—it does indeed work! Looks like there is no way to configure that to automatically happen with the "browserify":{}
config within package.json, but it does work from the command line, and (I would assume) through the programmatic invocation interface as well.
I'd vote to have that caveat mentioned in the documentation, but thanks for the response and for making a very useful tool!
@jwalton Good to know the --global-transform
option. Thanks!
I have an project that requires a library which uses the request library. For it to work in the browser i have to swap that for the browser-request. Is there a way for aliasify to update requires in dependencies?