Provide a flag for controlling the dart2js optimization level when building for web targets (#101945)
This commit is contained in:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user