Skip to content

Commit dd2f575

Browse files
committed
fix(hmr): fix hot module replacement in extension
1 parent 7d2fa14 commit dd2f575

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

scripts/prepare.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ import { watch } from 'chokidar';
55
import fs from 'fs-extra';
66

77
import { writeManifest } from './manifest';
8-
import { isDev, port, resolveParent } from './utils';
8+
import { isDev, resolveParent } from './utils';
99

1010
/**
1111
* Replace index.html with link to vite localhost for hot reload
1212
* @param view the view to replace
1313
*/
1414
const copyIndexHtml = async (view: string) => {
1515
fs.ensureDirSync(resolveParent(`dist/views/${view}`));
16-
const data = fs
17-
.readFileSync(resolveParent(`src/views/${view}/index.html`), 'utf-8')
18-
.replace('"./main.ts"', `"http://localhost:${port}/views/${view}/main.ts"`)
19-
.replace('<div id="app"></div>', '<div id="app">Vite server did not start</div>');
16+
const data = fs.readFileSync(resolveParent(`src/views/${view}/index.html`), 'utf-8').replace(
17+
'<script type="module" src="./main.ts"></script>',
18+
`<script type="module" src="http://localhost:3303/@vite/client"></script>
19+
<script type="module" src="http://localhost:3303/views/popup/main.ts"></script>`,
20+
);
2021
fs.writeFileSync(resolveParent(`dist/views/${view}/index.html`), data, 'utf-8');
2122
console.log(`Stubbing '${view}' to '${__dirname}/dist/views/${view}/index.html'`);
2223
};

src/components/AboutView.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ const show = ref(false);
66

77
<template>
88
<div class="about">
9-
<h1>This is an about page</h1>
9+
<h1>This is an about page !</h1>
1010
</div>
1111
</template>
1212

1313
<style scoped>
1414
.about {
1515
display: flex;
1616
justify-content: center;
17-
color: red;
17+
color: green;
1818
}
1919
</style>

0 commit comments

Comments
 (0)