Skip to content

Commit

Permalink
fix: Add logs when a hot reload happens
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Jul 14, 2023
1 parent 602dd42 commit 977246f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/core/utils/getInternalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export async function getInternalConfig(
);
finalConfig.vite.plugins.push(plugins.devServerGlobals(finalConfig));
finalConfig.vite.plugins.push(plugins.tsconfigPaths(finalConfig));
finalConfig.vite.plugins.push(plugins.hmrLogger(finalConfig));

finalConfig.vite.define ??= {};
getGlobals(finalConfig).forEach((global) => {
Expand Down
25 changes: 25 additions & 0 deletions src/core/vite-plugins/hmrLogger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Plugin } from 'vite';
import { InternalConfig } from '../types';
import { relative } from 'path';
import pc from 'picocolors';

/**
* Log when HMR changes are fired
*/
export function hmrLogger(config: InternalConfig): Plugin {
return {
name: 'wxt:hmr-logger',
apply: 'serve',
handleHotUpdate(ctx) {
if (
ctx.file.startsWith(config.srcDir) &&
!ctx.file.startsWith(config.wxtDir) &&
!ctx.file.endsWith('.html')
) {
config.logger.info(
'Hot reload: ' + pc.dim(relative(process.cwd(), ctx.file)),
);
}
},
};
}
1 change: 1 addition & 0 deletions src/core/vite-plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './multipageMove';
export * from './unimport';
export * from './virtualEntrypoint';
export * from './tsconfigPaths';
export * from './hmrLogger';
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function createServer(
if (changes.type === 'no-change') return;

// Log the entrypoints that were effected
consola.info(
internalConfig.logger.info(
`Changed: ${Array.from(new Set(fileChanges.map((change) => change[1])))
.map((file) => pc.dim(relative(internalConfig.root, file)))
.join(', ')}`,
Expand Down

0 comments on commit 977246f

Please sign in to comment.