Unverified Commit d05d4343 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Provide a flag for controlling the dart2js optimization level when building...

Provide a flag for controlling the dart2js optimization level when building for web targets (#101945)
parent df8d0eac
......@@ -63,7 +63,10 @@ class BuildWebCommand extends BuildSubCommand {
'The value has to start and end with a slash "/". '
'For more information: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base'
);
argParser.addOption('dart2js-optimization',
help: 'Sets the optimization level used for Dart compilation to JavaScript. '
'Valid values range from O0 to O4.'
);
}
@override
......@@ -120,6 +123,7 @@ class BuildWebCommand extends BuildSubCommand {
boolArg('source-maps'),
boolArg('native-null-assertions'),
baseHref,
stringArg('dart2js-optimization'),
);
return FlutterCommandResult.success();
}
......
......@@ -302,6 +302,7 @@ class ResidentWebRunner extends ResidentRunner {
true,
debuggingOptions.nativeNullAssertions,
null,
null,
);
}
await device.device.startApp(
......@@ -375,6 +376,7 @@ class ResidentWebRunner extends ResidentRunner {
true,
debuggingOptions.nativeNullAssertions,
kBaseHref,
null,
);
} on ToolExit {
return OperationResult(1, 'Failed to recompile application.');
......
......@@ -25,6 +25,7 @@ Future<void> buildWeb(
bool sourceMaps,
bool nativeNullAssertions,
String? baseHref,
String? dart2jsOptimization,
) async {
final bool hasWebPlugins = (await findPlugins(flutterProject))
.any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey));
......@@ -51,6 +52,8 @@ Future<void> buildWeb(
kNativeNullAssertions: nativeNullAssertions.toString(),
if (serviceWorkerStrategy != null)
kServiceWorkerStrategy: serviceWorkerStrategy,
if (dart2jsOptimization != null)
kDart2jsOptimization: dart2jsOptimization,
...buildInfo.toBuildSystemEnvironment(),
},
artifacts: globals.artifacts!,
......
......@@ -90,7 +90,7 @@ void main() {
final BuildCommand buildCommand = BuildCommand();
final CommandRunner<void> runner = createTestCommandRunner(buildCommand);
setupFileSystemForEndToEndTest(fileSystem);
await runner.run(<String>['build', 'web', '--no-pub', '--dart-define=foo=a']);
await runner.run(<String>['build', 'web', '--no-pub', '--dart-define=foo=a', '--dart2js-optimization=O3']);
expect(fileSystem.file(fileSystem.path.join('lib', 'generated_plugin_registrant.dart')).existsSync(), true);
}, overrides: <Type, Generator>{
......@@ -106,6 +106,7 @@ void main() {
'SourceMaps': 'false',
'NativeNullAssertions': 'true',
'ServiceWorkerStrategy': 'offline-first',
'Dart2jsOptimization': 'O3',
'BuildMode': 'release',
'DartDefines': 'Zm9vPWE=,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==',
'DartObfuscation': 'false',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment