Document how to avoid relative paths hell
See original GitHub issueThe paths
option, that forwards to https://github.com/defunctzombie/node-browser-resolve is not documented here
In my browserify app, for my private JS code, I don’t want to use relative paths because it’s annoying when you move some code from one place to another to have to update all the relative paths. See http://stackoverflow.com/a/23608416/82609
It seems the paths option permits to make available your own js files like normal node modules. As far as I have seen it works pretty fine and the browserify app is being build without using relative paths.
The problem is that in my paths folders I have JSX React files that must be compiled to JS before being integrated by browserify. It seems browserify doesn’t transform these files unless I reference them with their relative paths. I don’t know if this is a bug or an intended behavior. I think it could be nice, for each path, to specify if we want it to be transformed by browserify or not. Currently my browserify bundle contains raw uncompiled JSX code, and it breaks at runtime.
Until now I did not find any clear solution on how to handle the relative paths everywhere
problem. I think it’s a pretty common problem that can be really annoying on large code base when refactoring. It’s also solved easily with requirejs so I guess it would be nice to document how to do it with browserify.
Issue Analytics
- State:
- Created 9 years ago
- Comments:25 (4 by maintainers)
Top GitHub Comments
The problem is that there are a ton of ways to do what you’re trying to do. For me, the best thing is just to put code in
node_modules/
so thatrequire()
will resolve them without any configuration necessary.For each of your modules in
node_modules/
, you can configure the package.json with its own browserify transform field. Then your transforms will be applied automatically and in such a way that changes to modules will be isolated from one another. That is really handy when you need to evolve a project over time so you don’t need to switch everything over at once. You can just update the pieces as you need to.