Skip to content

Commit

Permalink
feat: add watchPublicPlugin for Chrome extension #542 (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leizhenpeng authored Jul 6, 2024
1 parent 049e023 commit ac03f68
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion chrome-extension/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineConfig } from 'vite';
import { resolve } from 'path';
import libAssetsPlugin from '@laynezh/vite-plugin-lib-assets';
import makeManifestPlugin from './utils/plugins/make-manifest-plugin';
import { watchRebuildPlugin } from '@chrome-extension-boilerplate/hmr';
import { watchPublicPlugin, watchRebuildPlugin } from '@chrome-extension-boilerplate/hmr';

const rootDir = resolve(__dirname);
const libDir = resolve(rootDir, 'lib');
Expand All @@ -23,6 +23,7 @@ export default defineConfig({
libAssetsPlugin({
outputPath: outDir,
}),
watchPublicPlugin(),
makeManifestPlugin({ outDir }),
isDev && watchRebuildPlugin({ reload: true }),
],
Expand Down
1 change: 1 addition & 0 deletions packages/hmr/lib/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './watch-rebuild-plugin';
export * from './make-entry-point-plugin';
export * from './watch-public-plugin';
14 changes: 14 additions & 0 deletions packages/hmr/lib/plugins/watch-public-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { PluginOption } from 'vite';
import fg from 'fast-glob';

export function watchPublicPlugin(): PluginOption {
return {
name: 'watch-public-plugin',
async buildStart() {
const files = await fg(['public/**/*']);
for (const file of files) {
this.addWatchFile(file);
}
},
};
}
1 change: 1 addition & 0 deletions packages/hmr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@rollup/plugin-sucrase": "^5.0.2",
"@types/ws": "^8.5.10",
"esm": "^3.2.25",
"fast-glob": "^3.3.2",
"rollup": "^4.18.0",
"ts-node": "^10.9.2"
}
Expand Down
28 changes: 28 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ac03f68

Please sign in to comment.