-
-
Notifications
You must be signed in to change notification settings - Fork 315
Enable hotreload #807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Enable hotreload #807
Changes from 4 commits
b8ce852
28dd86a
f56e2f9
d585d02
ec0457c
d87d179
0b06458
2a2bb0c
f8111c2
dd4f59c
6ebc7e3
e4cc9d1
6b1d64a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,4 +162,4 @@ packages: | |
| source: hosted | ||
| version: "3.1.2" | ||
| sdks: | ||
| dart: ">=3.6.0 <4.0.0" | ||
| dart: ">=3.8.0 <4.0.0" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,12 +32,13 @@ abstract class DevCommand extends BaseCommand with ProxyHelper, FlutterHelper { | |
| 'mode', | ||
| abbr: 'm', | ||
| help: 'Sets the reload/refresh mode.', | ||
| allowed: ['reload', 'refresh'], | ||
| allowed: ['reload', 'restart', 'refresh'], | ||
| allowedHelp: { | ||
| 'reload': 'Reloads js modules without server reload (loses current state)', | ||
| 'reload': 'Hot-reloads both client and server apps', | ||
| 'restart': 'Restarts the client app (loses current state)', | ||
| 'refresh': 'Performs a full page refresh and server reload', | ||
| }, | ||
| defaultsTo: 'refresh', | ||
| defaultsTo: 'reload', | ||
| ); | ||
| argParser.addOption( | ||
| 'port', | ||
|
|
@@ -57,6 +58,7 @@ abstract class DevCommand extends BaseCommand with ProxyHelper, FlutterHelper { | |
| argParser.addFlag('debug', abbr: 'd', help: 'Serves the app in debug mode.', negatable: false); | ||
| argParser.addFlag('release', abbr: 'r', help: 'Serves the app in release mode.', negatable: false); | ||
| argParser.addFlag('experimental-wasm', help: 'Compile to wasm', negatable: false); | ||
| argParser.addOption('module-format', help: 'The module format to use.', allowed: ['ddc', 'amd']); | ||
| argParser.addFlag( | ||
| 'managed-build-options', | ||
| help: | ||
|
|
@@ -85,6 +87,7 @@ abstract class DevCommand extends BaseCommand with ProxyHelper, FlutterHelper { | |
| late final port = argResults!.option('port') ?? project.port ?? defaultServePort; | ||
| late final customProxyPort = argResults!.option('proxy-port') ?? serverProxyPort; | ||
| late final useWasm = argResults!.flag('experimental-wasm'); | ||
| late final moduleFormat = argResults!.option('module-format'); | ||
| late final managedBuildOptions = argResults!.flag('managed-build-options'); | ||
| late final skipServer = argResults!.flag('skip-server'); | ||
|
|
||
|
|
@@ -282,7 +285,7 @@ abstract class DevCommand extends BaseCommand with ProxyHelper, FlutterHelper { | |
| project.checkWasmSupport(); | ||
| } | ||
|
|
||
| logger.write('Starting web compilers...', tag: Tag.cli, progress: ProgressState.running); | ||
| logger.write('Starting web compiler...', tag: Tag.cli, progress: ProgressState.running); | ||
|
|
||
| final compiler = useWasm | ||
| ? 'dart2wasm' | ||
|
|
@@ -312,16 +315,26 @@ abstract class DevCommand extends BaseCommand with ProxyHelper, FlutterHelper { | |
| for (final e in dartDefines.entries) '-D${e.key}=${e.value}', | ||
| ]; | ||
|
|
||
| final reloadConfig = switch (mode) { | ||
| 'reload' => ReloadConfiguration.hotReload, | ||
| 'refresh' => ReloadConfiguration.liveReload, | ||
| 'restart' || _ => ReloadConfiguration.hotRestart, | ||
| }; | ||
|
|
||
| final moduleFormat = reloadConfig == ReloadConfiguration.hotReload ? 'ddc' : this.moduleFormat ?? 'ddc'; | ||
| final usesDdcLibraryBundles = moduleFormat == 'ddc'; | ||
|
|
||
| List<String> additionalFlutterBuildArgs() { | ||
| final sdkKernelPath = p.url.join( | ||
| 'kernel', | ||
| flutterVersion.compareTo('3.32.0') >= 0 ? 'ddc_outline.dill' : 'ddc_outline_sound.dill', | ||
| ); | ||
| final librariesPath = p.join(webSdkDir, 'libraries.json'); | ||
| final ddcSdkPrefix = usesDdcLibraryBundles ? 'ddcLibraryBundle-canvaskit' : 'amd-canvaskit'; | ||
| final sdkJsPath = p.join( | ||
| webSdkDir, | ||
| 'kernel', | ||
| flutterVersion.compareTo('3.32.0') >= 0 ? 'amd-canvaskit' : 'amd-canvaskit-sound', | ||
| flutterVersion.compareTo('3.32.0') >= 0 ? ddcSdkPrefix : '$ddcSdkPrefix-sound', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Slightly unrelated, but I guess we can remove this (and related) handling now. The package's SDK constraint requires Dart 3.8 or later, so Flutter 3.32 or later is required anyway.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll keep it just a bit longer, but yes then I will remove it. |
||
| ); | ||
| return [ | ||
| '--define=build_web_compilers:entrypoint=use-ui-libraries=true', | ||
|
|
@@ -342,11 +355,32 @@ abstract class DevCommand extends BaseCommand with ProxyHelper, FlutterHelper { | |
| } | ||
|
|
||
| final buildArgs = [ | ||
| // Enable build_runner debugging | ||
| // '--force-jit', | ||
| // '--dart-jit-vm-arg=--observe', | ||
| // '--dart-jit-vm-arg=--pause-isolates-on-start', | ||
| if (release) '--release', | ||
| '--delete-conflicting-outputs', | ||
| if (managedBuildOptions) ...[ | ||
| '--define=build_web_compilers:ddc=generate-full-dill=true', | ||
| '--define=build_web_compilers:entrypoint=compiler=$compiler', | ||
|
|
||
| // Add DDC Library Bundle defines. | ||
| if (usesDdcLibraryBundles) ...[ | ||
| '--define=build_web_compilers:ddc=ddc-library-bundle=true', | ||
| '--define=build_web_compilers:sdk_js=ddc-library-bundle=true', | ||
| '--define=build_web_compilers:entrypoint=ddc-library-bundle=true', | ||
| '--define=build_web_compilers:entrypoint_marker=ddc-library-bundle=true', | ||
| ], | ||
|
|
||
| // Add Web Hot Reload defines. | ||
| if (reloadConfig == ReloadConfiguration.hotReload) ...[ | ||
| '--define=build_web_compilers:sdk_js=web-hot-reload=true', | ||
| '--define=build_web_compilers:entrypoint=web-hot-reload=true', | ||
| '--define=build_web_compilers:entrypoint_marker=web-hot-reload=true', | ||
| '--define=build_web_compilers:ddc=web-hot-reload=true', | ||
| '--define=build_web_compilers:ddc_modules=web-hot-reload=true', | ||
| ], | ||
|
Comment on lines
+382
to
+397
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should all of these only be added if the |
||
| switch (compiler) { | ||
| 'dartdevc' => '--define=build_web_compilers:ddc=environment=${jsonEncode(ddcDefines)}', | ||
| _ => '--define=build_web_compilers:entrypoint=${compiler}_args=${jsonEncode(dart2jsDefines)}', | ||
|
|
@@ -360,8 +394,10 @@ abstract class DevCommand extends BaseCommand with ProxyHelper, FlutterHelper { | |
| buildArgs, | ||
| logger, | ||
| guardResource, | ||
| enableDebugging: launchInChrome, | ||
| reload: mode == 'reload' ? ReloadConfiguration.hotRestart : ReloadConfiguration.liveReload, | ||
| enableDebugging: true, | ||
| useDwdsWebSocketConnection: !launchInChrome, | ||
| reload: reloadConfig, | ||
| moduleFormat: moduleFormat, | ||
| ); | ||
| if (workflow == null) { | ||
| return null; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider changing this to a private enum, then any conditional handling can validate you handled each case and spelling mistakes are avoided.