From 17c0953ef088c91a9897d74e16332dded04add0c Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 17 Oct 2025 22:52:21 +0200 Subject: [PATCH 1/3] Compile client code with dart2wasm --- site/build.yaml | 16 ++++++++++++++++ tool/dash_site/lib/src/commands/build.dart | 1 + tool/dash_site/lib/src/commands/serve.dart | 7 +++++++ 3 files changed, 24 insertions(+) diff --git a/site/build.yaml b/site/build.yaml index d1cff3e7ae..7982b9e419 100644 --- a/site/build.yaml +++ b/site/build.yaml @@ -7,3 +7,19 @@ builders: - "lib/src/style_hash.dart" auto_apply: root_package build_to: source + +targets: + $default: + builders: + build_web_compilers:entrypoint: + dev_options: + compilers: + dartdevc: + release_options: + # Use production compilers for release builds, and ensure + # kReleaseMode in jaspr is enabled. + compilers: + dart2js: + args: [-O4, -Djaspr.flags.release=true] + dart2wasm: + args: [-O4, -Djaspr.flags.release=true] diff --git a/tool/dash_site/lib/src/commands/build.dart b/tool/dash_site/lib/src/commands/build.dart index bcb958ac3c..45dbe4f309 100644 --- a/tool/dash_site/lib/src/commands/build.dart +++ b/tool/dash_site/lib/src/commands/build.dart @@ -37,6 +37,7 @@ final class BuildSiteCommand extends Command { 'run', 'jaspr_cli:jaspr', 'build', + '--no-managed-build-options', '--sitemap-domain=https://dart.dev', '--dart-define=PRODUCTION=$productionRelease', ], diff --git a/tool/dash_site/lib/src/commands/serve.dart b/tool/dash_site/lib/src/commands/serve.dart index ae53d4f13b..b4a67ece18 100644 --- a/tool/dash_site/lib/src/commands/serve.dart +++ b/tool/dash_site/lib/src/commands/serve.dart @@ -11,8 +11,13 @@ final class ServeSiteCommand extends Command { @override String get name => 'serve'; + ServeSiteCommand() { + argParser.addFlag('release', defaultsTo: false); + } + @override Future run() async { + final release = argResults!.flag('release'); installJasprCliIfNecessary(); final process = await Process.start( @@ -23,7 +28,9 @@ final class ServeSiteCommand extends Command { 'run', 'jaspr_cli:jaspr', 'serve', + '--no-managed-build-options', '--dart-define=PRODUCTION=false', + if (release) '--release', ], workingDirectory: 'site', runInShell: true, From 168f1ca775180891a96621463aebd1cafecb9b9e Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Fri, 17 Oct 2025 23:05:30 +0200 Subject: [PATCH 2/3] Comments --- tool/dash_site/lib/src/commands/build.dart | 2 ++ tool/dash_site/lib/src/commands/serve.dart | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tool/dash_site/lib/src/commands/build.dart b/tool/dash_site/lib/src/commands/build.dart index 45dbe4f309..caf5467cb0 100644 --- a/tool/dash_site/lib/src/commands/build.dart +++ b/tool/dash_site/lib/src/commands/build.dart @@ -37,6 +37,8 @@ final class BuildSiteCommand extends Command { 'run', 'jaspr_cli:jaspr', 'build', + // Use build_web_compiler options specified in build.yaml instead of + // those specified by jaspr_cli. '--no-managed-build-options', '--sitemap-domain=https://dart.dev', '--dart-define=PRODUCTION=$productionRelease', diff --git a/tool/dash_site/lib/src/commands/serve.dart b/tool/dash_site/lib/src/commands/serve.dart index b4a67ece18..098b661562 100644 --- a/tool/dash_site/lib/src/commands/serve.dart +++ b/tool/dash_site/lib/src/commands/serve.dart @@ -12,7 +12,11 @@ final class ServeSiteCommand extends Command { String get name => 'serve'; ServeSiteCommand() { - argParser.addFlag('release', defaultsTo: false); + argParser.addFlag( + 'release', + defaultsTo: false, + help: 'Build with compilers used for release builds instead of dartdevc.', + ); } @override @@ -28,6 +32,8 @@ final class ServeSiteCommand extends Command { 'run', 'jaspr_cli:jaspr', 'serve', + // Use build_web_compiler options specified in build.yaml instead of + // those specified by jaspr_cli. '--no-managed-build-options', '--dart-define=PRODUCTION=false', if (release) '--release', From 2510791047f4c810fccf05c8dcbd21fd43d90cb0 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Wed, 22 Oct 2025 23:34:00 +0200 Subject: [PATCH 3/3] Compile with -O2 --- site/build.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/site/build.yaml b/site/build.yaml index 7982b9e419..27aa18cfd4 100644 --- a/site/build.yaml +++ b/site/build.yaml @@ -22,4 +22,6 @@ targets: dart2js: args: [-O4, -Djaspr.flags.release=true] dart2wasm: - args: [-O4, -Djaspr.flags.release=true] + # Use -O2 to catch more potential runtime issues, it is not much + # slower than -O4: https://github.com/dart-lang/site-www/pull/6953#discussion_r2453318668 + args: [-O2, -Djaspr.flags.release=true]