Refactor dynamic require statements
Anything along the lines of:
var dynamicRequire = ...;
var resultingModule = require(dynamicRequire);
Unless this is an artifact of the build process, it seems to me that it is unnecessary and breaks software like crcn/nexe.
yes, it is intentional for the build process, basically this makes browserify to not bundle that dependency, so it's used for any dependency that I don't want in the main browser bundle. there are other similar issues reported, but unfortunately, I think I haven't yet seen a nice solution that can make all bundling tools/module systems happy. I would be very happy if we can find it.
Would explicitly excluding those modules in your browserify configuration work? https://github.com/substack/node-browserify#bexcludefile
it could be better, but one problem I see with that is, that won't work for people using this is as a dependency, browserify config is not inherited (I wish browserify supported inline comments for this stuff, like jshint for example)
This also causes warnings like this in dependent libraries with Webpack.
One way to fix this would be to refactor env-specific modules to be functions accepting isClientSide as an argument. Then you would be able to use browser field in package.json (respected by all major bundlers) to “remap” these files to browser versions that inject true there.
You can see this technique in action here.
thanks @gaearon I want to do some refactor on the bundling process, but yes I've been looking to have a mechandism that makes at least browserify and webpack happy, I'm just not familiar with webpack, but if package.json browser is something both respect (even when entering into dependencies) that might be the perfect solution.
if package.json browser is something both respect (even when entering into dependencies) that might be the perfect solution.
I can confirm this is the case.
awesome!, pasting this here for reference https://github.com/defunctzombie/package-browser-field-spec
I believe this has been resolved.