-
Notifications
You must be signed in to change notification settings - Fork 155
hot module replacement for local imports! #235
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
Conversation
3d66f51
to
985eeb3
Compare
985eeb3
to
0d15763
Compare
@@ -1,6 +1,6 @@ | |||
import "https://cdn.jsdelivr.net/npm/d3/+esm"; | |||
import {bar} from "../bar/bar.js"; | |||
export {top} from "../_import/top.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing a bug!
This comment was marked as resolved.
This comment was marked as resolved.
src/files.ts
Outdated
@@ -18,20 +18,10 @@ export function fileReference(name: string, sourcePath: string): FileReference { | |||
return { | |||
name, | |||
mimeType: mime.getType(name), | |||
path: normalizeRelativePath(relativeUrl(sourcePath, `/_file/${dirname(sourcePath)}/${name}`)) | |||
path: relativeUrl(sourcePath, `/_file/${dirname(sourcePath)}/${name}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this was a bug. Fixed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A side effect is that the file's hash is baked in the build:
const {foo} = await import("../_import/javascript/foo.js?sha=92cd58cd10d9a20a34eaa4ac95ca324f16e33da431bd103f6afb019e2933be7e");
I don't think it's a problem (it even ensures cache busting on poorly configured hosts). But if it's intended as a feature, maybe mention it in the documentation?
This computes the content hash of an imported ES module and its transitive imports. This ensures that when you import a.js, and a.js imports b.js, and b.js changes, that you get a new copy of a.js.
In addition, in
refreshAttachment
we now detect when an import references a changed file; in this case, instead of simplying send a refresh↓, we trigger a recompilation of the JavaScript to resolve new content hashes and rediscover which files to watch. (I took the lazy route here and re-parsed the entire Markdown file, but that should be fast enough since we do it on every save anyway.)Fixes #146.