Skip to content
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

Solve discussion #1070 #1077

Merged
merged 3 commits into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions packages/start/server/routeDataHmr.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
// @ts-nocheck
import generate from "@babel/generator";
import template from "@babel/template";
import _generate from "@babel/generator";
import _template from "@babel/template";
import crypto from "crypto";

/**
* NOTE: @babel/generator and @babel/template have not
* publish esm vision.
* detail: https://github.com/babel/babel/issues/15269#issue-1494499461
*
*/
const generate = typeof _generate.default == 'function' ? _generate.default : _generate
const template = typeof _template.default == 'function' ? _template.default : _template

export default function routeDataHmr() {
return {
visitor: {
Program(path) {
const result = generate.default(path.node);
const result = generate(path.node);
const hash = crypto.createHash("sha256").update(result.code).digest("base64");
const modHash = path.scope.generateUidIdentifier("modHash").name;
const statements = template.default.ast(`
const statements = template.ast(`
export const ${modHash} = "${hash}";
if (import.meta.hot) {
import.meta.hot.data.modHash = ${modHash};
Expand Down
Loading