From 8c787d01e8bd2fb344e7d335cfcee0c2ec98a3c4 Mon Sep 17 00:00:00 2001 From: jiangWeixian Date: Fri, 24 Sep 2021 23:02:08 +0800 Subject: [PATCH] :bug: hmr --- .eslintignore | 2 +- scripts/prepare.ts | 5 +++++ src/components/Logo.tsx | 5 +++++ src/components/Logo.vue | 5 ----- src/components/README.md | 11 ----------- src/hmr.ts | 6 ++++++ src/options/index.html | 1 + src/popup/index.html | 1 + vite.config.ts | 5 ++--- 9 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 src/components/Logo.tsx delete mode 100644 src/components/Logo.vue delete mode 100644 src/components/README.md create mode 100644 src/hmr.ts diff --git a/.eslintignore b/.eslintignore index e6a8276..c66e0ed 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,3 @@ dist node_modules -public +public \ No newline at end of file diff --git a/scripts/prepare.ts b/scripts/prepare.ts index 3333649..d963bc8 100644 --- a/scripts/prepare.ts +++ b/scripts/prepare.ts @@ -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( + //g, + ``, + ) .replace('
', '
Vite server did not start
') await fs.writeFile(r(`extension/dist/${view}/index.html`), data, 'utf-8') log('PRE', `stub ${view}`) diff --git a/src/components/Logo.tsx b/src/components/Logo.tsx new file mode 100644 index 0000000..24898ab --- /dev/null +++ b/src/components/Logo.tsx @@ -0,0 +1,5 @@ +import React from 'react' + +export const Logo = () => { + return
logo
+} diff --git a/src/components/Logo.vue b/src/components/Logo.vue deleted file mode 100644 index e135b9b..0000000 --- a/src/components/Logo.vue +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/src/components/README.md b/src/components/README.md deleted file mode 100644 index f9ed8ea..0000000 --- a/src/components/README.md +++ /dev/null @@ -1,11 +0,0 @@ -## Components - -Components in this dir will be auto-registered and on-demand, powered by [`vite-plugin-components`](https://github.com/antfu/vite-plugin-components). - -Components can be shared in all views. - -### Icons - -You can use icons from almost any icon sets by the power of [Iconify](https://iconify.design/). - -It will only bundle the icons you use. Check out [vite-plugin-icons](https://github.com/antfu/vite-plugin-icons) for more details. diff --git a/src/hmr.ts b/src/hmr.ts new file mode 100644 index 0000000..ad9d230 --- /dev/null +++ b/src/hmr.ts @@ -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 diff --git a/src/options/index.html b/src/options/index.html index 3208905..f945c68 100644 --- a/src/options/index.html +++ b/src/options/index.html @@ -6,6 +6,7 @@
+ diff --git a/src/popup/index.html b/src/popup/index.html index 9f4e6ae..9af79cf 100644 --- a/src/popup/index.html +++ b/src/popup/index.html @@ -6,6 +6,7 @@
+ \ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts index 0ce9326..141d960 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -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' @@ -17,7 +17,7 @@ export const sharedConfig: UserConfig = { }, plugins: [ // bad - // react(), + react(), AutoImport({ imports: [ { @@ -43,7 +43,6 @@ export const sharedConfig: UserConfig = { } export default defineConfig(({ command }) => { - console.log(command) return { ...sharedConfig, base: command === 'serve' ? `http://localhost:${port}/` : undefined,