-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Live-reload #2
Comments
Hey @guybedford: So I've done a bunch of investigation into the way Webpack's Hot Module replacement works. It's complicated, but it convinced me that I've undercooked the work I've done so far. I've had a bunch of things rattling around in my head for a while but I think it's time to put them down into something coherent. So, let's begin! Live-reloading CSSConsidering this as an example. If a CSS file has no exports (your bog-standard, old school CSS), then loading it involves simply creating a If the CSS file exports some variables (CSS Modules style), you need to propagate the change up the dependency tree. So if Live-reloading JSThere's no telling what a JS file might do, so we can't just arbitrarily reload a file. But we do need a way to say that some files are idempotent and totally ok to be reloaded. There's a couple of ways I can see this going:
The second is what Webpack does, with We should solve once for all file typesIt's quite easy for a CSS or JSX loader to add a chunk of JS at the end of a file, that's what plugin-live-jsx does, and what a few of the Webpack loaders do. The current jspm-server needs the plugin to identify itself as being hot-reload compatible, but that means that normal JS files can't be included. I think we should come up with a simple mechanism to pass metadata from a file to the loader, something like:
That later can be looked up, so if a new version of Not sure on the internals to support this, but thought I'd kick off the discussion. |
I like the idea of a meta export |
How about something like this: export let __hotReload = RELOAD_CONFIG
// where RELOAD CONFIG can be one of
true // I'm safe to be reloaded, but I can't do it myself. Tell my parents to see if they can reload me
false // if anything happens, reload the whole browser (default)
function() // called before a reload (to do any cleanup), returns maybe true/false whether to pass the reload up the chain Not sure what arguments to the function would be. Maybe pass in the loader instance? Dunno if it's needed. But, this would allow arbitrary unloading (the idea of a export let __hotReload = (plugin, newModule) => {
plugin.removeElement(this)
plugin.createElement(newModule)
return this.default.values != newModule.default.values
} Something like that could work... |
Got a couple working today:
|
Made a bunch more progress. Wondering, for those not using ES6, should we allow module.exports.__hotReload = true as well? There's no way for an CJS file to export a named ES6 export is there? |
In SystemJS 0.17, named exports are copied down as the enumerable properties of the default to the Module exports themselves, so this would be allowed. |
Wait, really? So setting import { a } from "./cjs.js"
a // 5 but you can also do import x from "./cjs.js"
x.a // 5 |
Yes exactly. |
That's cool! Can't wait for 0.17 😄 |
This is now built in, but needs to be documented. |
CSS files can be live-reloaded no problem, need to make sure jspm-server is up to date with them
The text was updated successfully, but these errors were encountered: