Skip to content

Commit a7f9ebc

Browse files
authored
Reorganize CLI flags for build web (#121837)
Reorganize CLI flags for `build web`
1 parent 9cb7a15 commit a7f9ebc

File tree

1 file changed

+44
-30
lines changed

1 file changed

+44
-30
lines changed

packages/flutter_tools/lib/src/commands/build_web.dart

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,20 @@ class BuildWebCommand extends BuildSubCommand {
2828
usesBuildNameOption();
2929
addBuildModeFlags(verboseHelp: verboseHelp, excludeDebug: true);
3030
usesDartDefineOption();
31-
usesWebRendererOption();
3231
addEnableExperimentation(hide: !verboseHelp);
3332
addNullSafetyModeOptions(hide: !verboseHelp);
3433
addNativeNullAssertions();
35-
argParser.addFlag('csp',
36-
negatable: false,
37-
help: 'Disable dynamic generation of code in the generated output. '
38-
'This is necessary to satisfy CSP restrictions (see http://www.w3.org/TR/CSP/).'
39-
);
40-
argParser.addFlag(
41-
'source-maps',
42-
help: 'Generate a sourcemap file. These can be used by browsers '
43-
'to view and debug the original source code of a compiled and minified Dart '
44-
'application.'
45-
);
46-
47-
if (featureFlags.isFlutterWebWasmEnabled) {
48-
argParser.addFlag(
49-
'wasm',
50-
help: 'Compile to WebAssembly rather than JavaScript (experimental).',
51-
);
52-
} else {
53-
// Add the flag as hidden. Will give a helpful error message in [runCommand] below.
54-
argParser.addFlag(
55-
'wasm',
56-
hide: true,
57-
);
58-
}
5934

35+
//
36+
// Flutter web-specific options
37+
//
38+
argParser.addSeparator('Flutter web options');
39+
argParser.addOption('base-href',
40+
help: 'Overrides the href attribute of the <base> tag in web/index.html. '
41+
'No change is done to web/index.html file if this flag is not provided. '
42+
'The value has to start and end with a slash "/". '
43+
'For more information: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base'
44+
);
6045
argParser.addOption('pwa-strategy',
6146
defaultsTo: kOfflineFirst,
6247
help: 'The caching strategy to be used by the PWA service worker.',
@@ -74,11 +59,22 @@ class BuildWebCommand extends BuildSubCommand {
7459
'is not desirable',
7560
},
7661
);
77-
argParser.addOption('base-href',
78-
help: 'Overrides the href attribute of the <base> tag in web/index.html. '
79-
'No change is done to web/index.html file if this flag is not provided. '
80-
'The value has to start and end with a slash "/". '
81-
'For more information: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base'
62+
usesWebRendererOption();
63+
64+
//
65+
// JavaScript compilation options
66+
//
67+
argParser.addSeparator('JavaScript compilation options');
68+
argParser.addFlag('csp',
69+
negatable: false,
70+
help: 'Disable dynamic generation of code in the generated output. '
71+
'This is necessary to satisfy CSP restrictions (see http://www.w3.org/TR/CSP/).'
72+
);
73+
argParser.addFlag(
74+
'source-maps',
75+
help: 'Generate a sourcemap file. These can be used by browsers '
76+
'to view and debug the original source code of a compiled and minified Dart '
77+
'application.'
8278
);
8379
argParser.addOption('dart2js-optimization',
8480
help: 'Sets the optimization level used for Dart compilation to JavaScript. '
@@ -93,6 +89,24 @@ class BuildWebCommand extends BuildSubCommand {
9389
help: 'Disables the frequency based minifier. '
9490
'Useful for comparing the output between builds.'
9591
);
92+
93+
//
94+
// Experimental options
95+
//
96+
if (featureFlags.isFlutterWebWasmEnabled) {
97+
argParser.addSeparator('Experimental options');
98+
argParser.addFlag(
99+
'wasm',
100+
help: 'Compile to WebAssembly rather than JavaScript.',
101+
negatable: false,
102+
);
103+
} else {
104+
// Add the flag as hidden. Will give a helpful error message in [runCommand] below.
105+
argParser.addFlag(
106+
'wasm',
107+
hide: true,
108+
);
109+
}
96110
}
97111

98112
final FileSystem _fileSystem;

0 commit comments

Comments
 (0)