-
Notifications
You must be signed in to change notification settings - Fork 80
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
feat: hot-update 文件生成放到 node_modules 下 #424
base: master
Are you sure you want to change the base?
Changes from 11 commits
2c1cc45
8e4c23b
caf9838
0bea63d
b79b5ca
9840c18
583d3e0
7d5f0b3
ae9e4fb
2befd13
8f097f7
5d1e91e
7bca4dc
39ac097
0a84860
b70b89a
859e09f
1f17c10
edea548
001c95f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -337,13 +337,13 @@ impl Compiler { | |
let (code, sourcemap) = | ||
self.generate_hmr_chunk(chunk, &filename, &modified_ids, current_full_hash)?; | ||
// TODO the final format should be {name}.{full_hash}.hot-update.{ext} | ||
self.write_to_dist(&filename, code); | ||
self.write_to_dist(format!("{}.map", &filename), sourcemap); | ||
self.write_to_hot_update_dir(&filename, code); | ||
self.write_to_hot_update_dir(format!("{}.map", &filename), sourcemap); | ||
} | ||
} | ||
let t_generate_hmr_chunk = t_generate_hmr_chunk.elapsed(); | ||
|
||
self.write_to_dist( | ||
self.write_to_hot_update_dir( | ||
format!("{}.hot-update.json", last_full_hash), | ||
serde_json::to_string(&HotUpdateManifest { | ||
removed_chunks, | ||
|
@@ -372,15 +372,28 @@ impl Compiler { | |
Ok(current_full_hash) | ||
} | ||
|
||
pub fn write_to_dist<P: AsRef<std::path::Path>, C: AsRef<[u8]>>( | ||
// pub fn write_to_dist<P: AsRef<std::path::Path>, C: AsRef<[u8]>>( | ||
// &self, | ||
// filename: P, | ||
// content: C, | ||
// ) { | ||
// let to = self.context.config.output.path.join(filename); | ||
|
||
// std::fs::write(to, content).unwrap(); | ||
// } | ||
|
||
pub fn write_to_hot_update_dir<P: AsRef<std::path::Path>, C: AsRef<[u8]>>( | ||
&self, | ||
filename: P, | ||
content: C, | ||
) { | ||
let to = self.context.config.output.path.join(filename); | ||
|
||
std::fs::write(to, content).unwrap(); | ||
let hmr_dir = self.context.root.join("node_modules/.mako/hot_update"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里用 node_modules/.mako,是不是 runtime 就不需要调整了,改动可以小一点。 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if !hmr_dir.exists() { | ||
fs::create_dir_all(&hmr_dir).unwrap(); | ||
} | ||
std::fs::write(hmr_dir.join(filename), content).unwrap(); | ||
} | ||
|
||
// 写入产物前记录 content 大小, 并加上 hash 值 | ||
pub fn write_to_dist_with_stats(&self, file: EmitFile) { | ||
let to: PathBuf = self.context.config.output.path.join(file.hashname.clone()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,7 +147,7 @@ function createRuntime(makoModules, entryModuleId) { | |
invalidate () {}, | ||
check () { | ||
const current_hash = requireModule.currentHash(); | ||
return fetch(`${requireModule.publicPath}${current_hash}.hot-update.json`).then((res)=>{ | ||
return fetch(`/hot_update/${current_hash}.hot-update.json`).then((res)=>{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里写死 会不会和用户的路由有冲突。业务有一个 hot_update/:id 的路由。这里可以参考下 umi 在 配置了 publicPath 这些资源是怎么 serve 的
|
||
return res.json(); | ||
}).then((update)=>{ | ||
return Promise.all(update.c.map((chunk)=>{ | ||
|
@@ -162,7 +162,7 @@ function createRuntime(makoModules, entryModuleId) { | |
ext | ||
].join('.'); | ||
return new Promise((done)=>{ | ||
const url = `${requireModule.publicPath}${hotChunkName}`; | ||
const url = `/hot_update/${hotChunkName}`; | ||
requireModule.loadScript(url, done); | ||
}); | ||
})); | ||
|
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.
之前 dev server 也写的仓促,有时间精力可以看下这部分有没有更加优雅的 crate 可以用。类似 express 一样 mout 。