browserify issues
drom opened this issue ยท 10 comments
Thank you for the great package!
We have little issue when trying to bundle X11 with our application with browserify.
In fact x11 will try to require extensions from /ext/
folder at runtime.
It would be nice to have option of requiring all extensions statically and not doing runtime require.
Hi @drom I think there are standard ways to work around this. Can you try solutions from http://stackoverflow.com/questions/21642398/compiling-dynamically-required-modules-with-browserify ?
Main reason to require dynamically is to reduce startup time, I expect node-x11 users to be really tiny utilities so few extra ms for initial load + compile would matter.
@sidorares thank you for the quick response. We will try workarounds and will let you know about our success.
Yes, require()
ing the wanted extentions in an unused function should do the trick, as long as Browserify resolves the paths to the same location.
@polpo @sidorares requiring extensions in xcore
works but I don't want to patch x11
package source code for that. Requiring in any other place can't seems to satisfy browserify ๐
@drom can you post example of 'requiring in any other place'? (ideally with browserify command line example so it's quicker for me to try)
I might add an entry point that requires all extensions at once if we don't find good solution, something like const x11 = require('x11'); x11.preloadAllExtensions();
This is just to add to @drom response:
In lib/xcore.js
the XClient.prototype.require
method has this line which requires the extensions in the ext/
directory:
line 564: ext = require('./ext/' + extName);
When we browserify our application it does not recognize the extensions, specifically, big-requests.js
, randr.js
, and render.js
.
Our solution was to add a function to the top of the lib/xcore.js
file which cached the require's to the extensions in use:
function requireExtensions() {
var bigRequests = require('./ext/big-requests');
var randr = require('./ext/randr');
var render = require('./ext/render');
}
Is there another way around this without modifying the x11 dependency? We took a look at the stackoverflow which recommended using the require-globify
dependency but we dont believe that that would help in this scenario.
@drom @ajgrande924 what happens if you add those lines to your code to force cache:
require('x11/lib/ext/randr')
require('x11/lib/ext/render')
require('x11/lib/ext/big-requests')
@sidorares here is the gist: https://gist.github.com/drom/d51ff72ff8953039cd4cbe1a0b916fda
I can't make it work unless it is exactly matching the string require('./ext/big-requests');
An that is part of the code. Witch means it need to be part of the code inside x11/lib/<<>>.js
that is xcore
or some file required by xcore
. This function will never be called so in node
environment it is dead code, but when browserified it will be taken into relevant cache.
thanks! I tried few examples and no success, most suggested solutions are for package own dynamic dependencies, not dependency dependencies.
Happy to accept pr with preloadAllExtensions()
as long as it's not called by default
@sidorares @polpo @ajgrande924 Thank you for the help! It works.