hot module replacement for local imports!#235
Merged
Conversation
3d66f51 to
985eeb3
Compare
985eeb3 to
0d15763
Compare
mbostock
commented
Nov 24, 2023
| @@ -1,6 +1,6 @@ | |||
| import "https://cdn.jsdelivr.net/npm/d3/+esm"; | |||
| import {bar} from "../bar/bar.js"; | |||
| export {top} from "../_import/top.js"; | |||
This comment was marked as resolved.
This comment was marked as resolved.
mbostock
commented
Nov 24, 2023
| name, | ||
| mimeType: mime.getType(name), | ||
| path: normalizeRelativePath(relativeUrl(sourcePath, `/_file/${dirname(sourcePath)}/${name}`)) | ||
| path: relativeUrl(sourcePath, `/_file/${dirname(sourcePath)}/${name}`) |
Member
Author
Member
Author
There was a problem hiding this comment.
Yes, this was a bug. Fixed!
Fil
approved these changes
Nov 26, 2023
Contributor
Fil
left a comment
There was a problem hiding this comment.
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
refreshAttachmentwe 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.