Open guybedford opened 8 years ago
For me this would ease the speed of NodeJS development in SystemJS considerably. What would be necessary in order to adapt hot-reloader to make this possible?
This would be useful in the main process of electron apps.
I now have this working with electron + jspm + typescript + react + mobx, for both the electron main process (which is node) and the renderer processes (which is a browser).
The starter project is at: https://github.com/AntonyBlakey/starter-electron-jspm-typescript-react-mobx and the reloader that it uses (a modified version of this one) is at: https://github.com/AntonyBlakey/systemjs-hot-reloader.
The key was to separate the reloader from the socket creation, because socket.io-client
needs to be imported differently in the two contexts. Also socket.io-client
refers to navigator.userAgent
without any guards (which IMO is a bug in that package), so you need to setup a fake global.
I don't have a fix for the jspm + typescript typings issue, but that's not too hard to work around either by replicating the jspm installs as npm installs, or symlinking automatically between jspm_packages/npm
and npm_modules
, or using typings to install from jspm_packages
@AntonyBlakey Would you be willing to bring your changes into this project. systemjs-hot-reloader
now has separate logic and eventing api. Perhaps at systemjs-hot-reloader/node
@alexisvincent Do you have an idea on how import {module} from '@hot'
could work on node?
We are currently trying to run our testcases on node. They can't be run because node is not aware of '@hot', obviously...
@mpfau This depends on what your tests are being transpiled to. How are you running your tests on node? (Since import from
is not valid node)
@alexisvincent found a workaround to stub @hot
in node
const Module = require('module').Module;
Module._cache['@hot'] = {exports: {module: undefined}}
const resolveFilenameNode = Module._resolveFilename
Module._resolveFilename = function(request, parent, isMain) {
if (request === '@hot') return request
return resolveFilenameNode(request, parent, isMain)
}
Very nice. Out of interest, what testing framework are you using.
We recently switched from tape to ospec (https://github.com/lhorie/mithril.js/tree/rewrite/ospec). It has been written by the very smart Leo Horie (author of mithril).
I wonder if it would be possible to create a variation of this project that works for Node apps running SystemJS? That could potentially just use the hot-reloader component with some built-in file watching method of sorts, that could just need to be imported to work.
Just putting this down here as a feature to consider, feel free to close as well.