Let's say you have a string that you want to include in browserify. This needs to be identified by a path so you can require it later, but a file does not exist at that path's location.
You can pass streams to browserify, and streams can include arbitrary strings... the key is ignoreMissing:true
which will dutifully ignore any required files that aren't actually on the file system.
Now, for it to actually come through as something you can require, it needs to be exposed as an explicit string. While this works, it means you can only reference it by this name... see with-expose.js
The main problem of course is that mechanisms for directory loading won't work like they do in a normal commonjs fashion.
i.e., consider the following was used for ./requires
:
require("./")
require("./index.js")()
require("./index")()
require("./dir1")()
require("./dir1/index")()
require("./dir1/index.js")()
require("./dir2")()
require("./dir2/index")()
require("./dir2/index.js")()
This would not work at all... the only reason the above works is because the modules have been exposed by an explicit name. It doesn't even matter that there is a ./
in front of them - they are not loading from the directories.
Now, the really frustrating part of all of this is that if you can trick browserify into thinking the file exists, then everything works properly. i.e., take a look at with-dummy-files.js
Then boom, it works. I'm not entirely convinced that browserify shouldn't throw an error if it can't find a file through resolve when a stream with the same file name has been provided