File tree Expand file tree Collapse file tree 3 files changed +30
-3
lines changed
Expand file tree Collapse file tree 3 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -502,11 +502,13 @@ def package_json_template(
502502 )
503503
504504
505- def vite_config_template (base : str ):
505+ def vite_config_template (base : str , hmr : bool , force_full_reload : bool ):
506506 """Template for vite.config.js.
507507
508508 Args:
509509 base: The base path for the Vite config.
510+ hmr: Whether to enable hot module replacement.
511+ force_full_reload: Whether to force a full reload on changes.
510512
511513 Returns:
512514 Rendered vite.config.js content as string.
@@ -537,12 +539,25 @@ def vite_config_template(base: str):
537539 }};
538540}}
539541
542+ function fullReload() {{
543+ return {{
544+ name: "full-reload",
545+ enforce: "pre",
546+ handleHotUpdate({{ server }}) {{
547+ server.ws.send({{
548+ type: "full-reload",
549+ }});
550+ return [];
551+ }}
552+ }};
553+ }}
554+
540555export default defineConfig((config) => ({{
541556 plugins: [
542557 alwaysUseReactDomServerNode(),
543558 reactRouter(),
544559 safariCacheBustPlugin(),
545- ],
560+ ].concat( { "[fullReload()]" if force_full_reload else "[]" } ) ,
546561 build: {{
547562 assetsDir: "{ base } assets".slice(1),
548563 rollupOptions: {{
@@ -564,6 +579,7 @@ def vite_config_template(base: str):
564579 }},
565580 server: {{
566581 port: process.env.PORT,
582+ hmr: { "true" if hmr else "false" } ,
567583 watch: {{
568584 ignored: [
569585 "**/.web/backend/**",
Original file line number Diff line number Diff line change @@ -640,6 +640,12 @@ class EnvironmentVariables:
640640 # Enable full logging of debug messages to reflex user directory.
641641 REFLEX_ENABLE_FULL_LOGGING : EnvVar [bool ] = env_var (False )
642642
643+ # Whether to enable hot module replacement
644+ VITE_HMR : EnvVar [bool ] = env_var (True )
645+
646+ # Whether to force a full reload on changes.
647+ VITE_FORCE_FULL_RELOAD : EnvVar [bool ] = env_var (False )
648+
643649
644650environment = EnvironmentVariables ()
645651
Original file line number Diff line number Diff line change 1010from reflex import constants
1111from reflex .compiler import templates
1212from reflex .config import Config , get_config
13+ from reflex .environment import environment
1314from reflex .utils import console , path_ops
1415from reflex .utils .prerequisites import get_project_hash , get_web_dir
1516from reflex .utils .registry import get_npm_registry
@@ -192,7 +193,11 @@ def _compile_vite_config(config: Config):
192193 base = "/"
193194 if frontend_path := config .frontend_path .strip ("/" ):
194195 base += frontend_path + "/"
195- return templates .vite_config_template (base = base )
196+ return templates .vite_config_template (
197+ base = base ,
198+ hmr = environment .VITE_HMR .get (),
199+ force_full_reload = environment .VITE_FORCE_FULL_RELOAD .get (),
200+ )
196201
197202
198203def initialize_vite_config ():
You can’t perform that action at this time.
0 commit comments