-
Notifications
You must be signed in to change notification settings - Fork 71
Description
Hi,
Firstly, thank-you for Hem: a fantastic tool that significantly simplifies my workflow!
I'm having a little bit of trouble understanding how I can use Hem with npm packages that don't have an index.js
file. For example, I'm trying to use Hem to allow my application to require files from the codemirror
npm package. I see that codemirror
has the following package.json
:
{
"name": "codemirror",
"version": "3.14.1",
"main": "lib/codemirror.js",
"directories": {
"lib": "./lib"
}
...
}
I have a number of questions related to this:
- When I try to
require('codemirror')
, Hem can't find the module and I receivemodule 'codemirror' not found
. This makes sense as there is no index.js file (and I see that Hem'sstitch.eco
looks for the path of an index file). Instead, I see that arequire('codemirror/lib/codemirror')
does work. Is there any workaround for this so that I can userequire('codemirror')
? lib/codemirror.js
exports a global variable ontowindow
, rather than ontomodule.exports
, like this:window.CodeMirror = (function() { ...
I see that Hem expects the CommonJS style, and so won't pick up this variable. I can changelib/codemirror.js
to store the variable onmodule.exports
, but I'd prefer not to change code that I don't own. Is there any workaround for this?- The
codemirror
npm package includes a number of additional JS files that I'd like to include, but they rely on the presence of the CodeMirror variable. I can issue a separate require statement for each:require('codemirror/lib/codemirror')
then arequire('codemirror/modes/javascript/javascript')
. However, this fails becausecodemirror/modes/javascript/javascript
assumes that it will be able to access the CodeMirror global variable, and I believe that Hem might be requiring files into a "sandboxed" environment where there is no access to other variables. The following doesn't work either:CodeMirror = require('codemirror/lib/codemirror')
followed by arequire('codemirror/modes/javascript/javascript')
. Any ideas? - The
codemirror
npm package includes a number of CSS files that I'd like to include in my application. Is there any support for this in Hem?
I'm using Spine as my application framework, and would prefer to use the npm dependencies rather than plain-old javascript files (i.e. Hem libs
) if possible.
If needed and of interest to the Hem developers, I would be happy to work on a patch to support any of the features above (though I would require a little help in designing solutions).
Thank-you in advance for answers or hints towards solving any of these questions.
Best,
Louis.