Skip to content

Commit

Permalink
🐛 hmr
Browse files Browse the repository at this point in the history
  • Loading branch information
JiangWeixian committed Sep 24, 2021
1 parent 79c3908 commit 8c787d0
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dist
node_modules
public
public
5 changes: 5 additions & 0 deletions scripts/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ async function stubIndexHtml() {
for (const view of views) {
await fs.ensureDir(r(`extension/dist/${view}`))
let data = await fs.readFile(r(`src/${view}/index.html`), 'utf-8')
console.log(data)
data = data
.replace('"./main.tsx"', `"http://localhost:${port}/${view}/main.tsx"`)
.replace(
/<!-- hmr -->/g,
`<script type="module" src="http://localhost:${port}/hmr.ts"></script>`,
)
.replace('<div id="app"></div>', '<div id="app">Vite server did not start</div>')
await fs.writeFile(r(`extension/dist/${view}/index.html`), data, 'utf-8')
log('PRE', `stub ${view}`)
Expand Down
5 changes: 5 additions & 0 deletions src/components/Logo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react'

export const Logo = () => {
return <div>logo</div>
}
5 changes: 0 additions & 5 deletions src/components/Logo.vue

This file was deleted.

11 changes: 0 additions & 11 deletions src/components/README.md

This file was deleted.

6 changes: 6 additions & 0 deletions src/hmr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @ts-nocheck
import RefreshRuntime from '/@react-refresh'
RefreshRuntime.injectIntoGlobalHook(window)
window.$RefreshReg$ = () => {}
window.$RefreshSig$ = () => (type) => type
window.__vite_plugin_react_preamble_installed__ = true
1 change: 1 addition & 0 deletions src/options/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</head>
<body>
<div id="app"></div>
<!-- hmr -->
<script type="module" src="./main.tsx"></script>
</body>
</html>
1 change: 1 addition & 0 deletions src/popup/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</head>
<body style="min-width: 100px">
<div id="root"></div>
<!-- hmr -->
<script type="module" src="./main.tsx"></script>
</body>
</html>
5 changes: 2 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig, UserConfig } from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
import WindiCSS from 'vite-plugin-windicss'
import react from '@vitejs/plugin-react'
import react from '@vitejs/plugin-react-refresh'
import windiConfig from './windi.config'
import { r, port, isDev } from './scripts/utils'

Expand All @@ -17,7 +17,7 @@ export const sharedConfig: UserConfig = {
},
plugins: [
// bad
// react(),
react(),
AutoImport({
imports: [
{
Expand All @@ -43,7 +43,6 @@ export const sharedConfig: UserConfig = {
}

export default defineConfig(({ command }) => {
console.log(command)
return {
...sharedConfig,
base: command === 'serve' ? `http://localhost:${port}/` : undefined,
Expand Down

0 comments on commit 8c787d0

Please sign in to comment.