allow to specify global-transforms
See original GitHub issueFor the sake of argument lets say I’m working on a project A which depends on point-generator
.
point-generator
depends on xtend
.
So now I’m trying to apply a transform to the index.js
file in xtend
.
To do that I’ll add my transform to the package.json
of my package A.
No transforms are specified in xtend
or its dependent package.json
s and my higher level transform doesn’t get called when node_modules/point-generator/node_modules/xtend/index.js
is resolved.
As a result I have no chance to transform xtend/index.js
since my transform is never called.
This is where global transforms could help. They would be called for EVERY file that is resolved, even the ones from child dependencies.
Lets take the example of browserify-swap
. With this I want to swap out modules when a certain configuration applies. So it would be called with all resolved files and try to match the regex and depending on the result apply a transform or just pass it through.
{
"browserify": {
"global-transform": [ "browserify-swap" ]
},
"browserify-swap": {
"dev": {
".*node_modules\/xtend\/\\S+\\.js$": "./swap/other-xtend.js"
},
"test": {
".*node_modules\/xtend\/\\S+\\.js$": "./swap/stubable-xtend.js"
}
}
}
Swapping makes sense for different use cases:
- only pulling large modules needed for diagnostics when a flag is set and otherwise replacing with empty stub, greatly speeding up bundling time when it’s not needed
- good example is
hyperwatch
which depends onhypernal
(huge)
- good example is
- stubbing out modules during testing
However I think there will be other situations where global transforms would be a great help.
To avoid non-determinism, local transforms should always execute first, so that their input cannot be affected by a global transform getting in the middle.
Additionally global transforms only apply if the package.json
that they are defined in is the root of the project (i.e. the current dir).
Issue Analytics
- State:
- Created 10 years ago
- Reactions:1
- Comments:5
Top GitHub Comments
@substack So what about global-transforms in package.json stuff?
Global transforms just landed in 3.17.0. I’m not sure about the
package.json
stuff but you can use them with-g
or via the API by doing.transform({ global: true }, tr)
.