From 3e11c21326270108cd2e00e5c0892608c2d495f7 Mon Sep 17 00:00:00 2001 From: Julien Ripouteau Date: Wed, 10 Apr 2024 23:10:08 +0200 Subject: [PATCH] feat: add serve `--hmr` flag --- commands/serve.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/commands/serve.ts b/commands/serve.ts index 2c6753c6..6aca306d 100644 --- a/commands/serve.ts +++ b/commands/serve.ts @@ -28,6 +28,11 @@ export default class Serve extends BaseCommand { '{{ binaryName }} serve --watch', '```', '', + 'You can also start the server with HMR support using the following command.', + '```', + '{{ binaryName }} serve --hmr', + '```', + '', 'The assets bundler dev server runs automatically after detecting vite config or webpack config files', 'You may pass vite CLI args using the --assets-args command line flag.', '```', @@ -41,6 +46,9 @@ export default class Serve extends BaseCommand { declare devServer: DevServer + @flags.boolean({ description: 'Start the server with HMR support' }) + declare hmr?: boolean + @flags.boolean({ description: 'Watch filesystem and restart the HTTP server on file change', alias: 'w', @@ -112,7 +120,14 @@ export default class Serve extends BaseCommand { return } + if (this.watch && this.hmr) { + this.logger.error('Cannot use --watch and --hmr flags together. Choose one of them') + this.exitCode = 1 + return + } + this.devServer = new assembler.DevServer(this.app.appRoot, { + hmr: this.hmr === true ? true : false, clearScreen: this.clear === false ? false : true, nodeArgs: this.parsed.nodeArgs, scriptArgs: [],