diff --git a/site/build.yaml b/site/build.yaml index d1cff3e7ae..27aa18cfd4 100644 --- a/site/build.yaml +++ b/site/build.yaml @@ -7,3 +7,21 @@ 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: + # 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] diff --git a/tool/dash_site/lib/src/commands/build.dart b/tool/dash_site/lib/src/commands/build.dart index bcb958ac3c..caf5467cb0 100644 --- a/tool/dash_site/lib/src/commands/build.dart +++ b/tool/dash_site/lib/src/commands/build.dart @@ -37,6 +37,9 @@ 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 ae53d4f13b..098b661562 100644 --- a/tool/dash_site/lib/src/commands/serve.dart +++ b/tool/dash_site/lib/src/commands/serve.dart @@ -11,8 +11,17 @@ final class ServeSiteCommand extends Command { @override String get name => 'serve'; + ServeSiteCommand() { + argParser.addFlag( + 'release', + defaultsTo: false, + help: 'Build with compilers used for release builds instead of dartdevc.', + ); + } + @override Future run() async { + final release = argResults!.flag('release'); installJasprCliIfNecessary(); final process = await Process.start( @@ -23,7 +32,11 @@ 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', ], workingDirectory: 'site', runInShell: true,