Skip to content

Commit 37066f6

Browse files
authored
Compile client code with dart2wasm (#6953)
This configures `build_web_compilers` to use ddc on dev builds (`dash_site serve`) while compiling with both `dart2js` and `dart2wasm` on release modes (`dash_site build`, or the added `--release` flag to `serve` to experiment with this more easily). Using jaspr CLI options to switch to dart2wasm would _only_ compile sources with `dart2wasm`, this uses both compilers and a feature detection snippet emitted by `dart2wasm` to determine which variant is used. That seems to be in spirit of #6854. To stop jaspr from overriding options passed to `build_web_compilers`, one needs to use the `--no-managed-build-options` flag. A downside is that the `PRODUCTION` define set on release modes would not be forwarded to client code any longer. The constant is only used in the `robots.txt` generator so this should be fine, forwarding this to client code would require more changes to `jaspr_cli`. Closes #6854.
1 parent d593f5e commit 37066f6

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

site/build.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,21 @@ builders:
77
- "lib/src/style_hash.dart"
88
auto_apply: root_package
99
build_to: source
10+
11+
targets:
12+
$default:
13+
builders:
14+
build_web_compilers:entrypoint:
15+
dev_options:
16+
compilers:
17+
dartdevc:
18+
release_options:
19+
# Use production compilers for release builds, and ensure
20+
# kReleaseMode in jaspr is enabled.
21+
compilers:
22+
dart2js:
23+
args: [-O4, -Djaspr.flags.release=true]
24+
dart2wasm:
25+
# Use -O2 to catch more potential runtime issues, it is not much
26+
# slower than -O4: https://github.com/dart-lang/site-www/pull/6953#discussion_r2453318668
27+
args: [-O2, -Djaspr.flags.release=true]

tool/dash_site/lib/src/commands/build.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ final class BuildSiteCommand extends Command<int> {
3737
'run',
3838
'jaspr_cli:jaspr',
3939
'build',
40+
// Use build_web_compiler options specified in build.yaml instead of
41+
// those specified by jaspr_cli.
42+
'--no-managed-build-options',
4043
'--sitemap-domain=https://dart.dev',
4144
'--dart-define=PRODUCTION=$productionRelease',
4245
],

tool/dash_site/lib/src/commands/serve.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@ final class ServeSiteCommand extends Command<int> {
1111
@override
1212
String get name => 'serve';
1313

14+
ServeSiteCommand() {
15+
argParser.addFlag(
16+
'release',
17+
defaultsTo: false,
18+
help: 'Build with compilers used for release builds instead of dartdevc.',
19+
);
20+
}
21+
1422
@override
1523
Future<int> run() async {
24+
final release = argResults!.flag('release');
1625
installJasprCliIfNecessary();
1726

1827
final process = await Process.start(
@@ -23,7 +32,11 @@ final class ServeSiteCommand extends Command<int> {
2332
'run',
2433
'jaspr_cli:jaspr',
2534
'serve',
35+
// Use build_web_compiler options specified in build.yaml instead of
36+
// those specified by jaspr_cli.
37+
'--no-managed-build-options',
2638
'--dart-define=PRODUCTION=false',
39+
if (release) '--release',
2740
],
2841
workingDirectory: 'site',
2942
runInShell: true,

0 commit comments

Comments
 (0)