Skip to content

Commit 3b09fd9

Browse files
committed
reuse web build in firebase web build
1 parent cb6c96b commit 3b09fd9

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed

packages/firebase_build/lib/src/app_build.dart

+10-19
Original file line numberDiff line numberDiff line change
@@ -66,35 +66,26 @@ class FlutterFirebaseWebAppOptions {
6666

6767
/// Convenient builder.
6868
class FlutterFirebaseWebAppBuilder implements CommonAppBuilder {
69+
late final FlutterWebAppBuilder _flutterWebAppBuilderOnly;
6970
final FlutterFirebaseWebAppOptions options;
7071

7172
/// Project path.
7273
@override
7374
String get path => options.path;
7475

75-
FlutterFirebaseWebAppBuilder({required this.options});
76+
FlutterFirebaseWebAppBuilder({required this.options}) {
77+
_flutterWebAppBuilderOnly = FlutterWebAppBuilder(
78+
options: FlutterWebAppOptions(
79+
buildOptions: options.buildOptions,
80+
path: options.path,
81+
deployDir: options.deployDir),
82+
);
83+
}
7684

7785
String get target => options.deployOptions.target;
7886

7987
Future<void> build({FirebaseWebAppActionController? controller}) async {
80-
var shell = Shell().cd(options.path);
81-
controller?.shell = shell;
82-
var renderOptions = '';
83-
var wasm = options.buildOptions?.wasm ?? false;
84-
if (!wasm) {
85-
// not compatible with wasm
86-
switch (options.buildOptions?.renderer) {
87-
case FlutterWebRenderer.html:
88-
renderOptions = ' --web-renderer html';
89-
break;
90-
case FlutterWebRenderer.canvasKit:
91-
renderOptions = ' --web-renderer canvaskit';
92-
break;
93-
default:
94-
}
95-
}
96-
var wasmOptions = wasm ? ' --wasm' : '';
97-
await shell.run('flutter build web$renderOptions$wasmOptions');
88+
await _flutterWebAppBuilderOnly.buildOnly();
9889
await firebaseWebAppBuildToDeploy(options.path,
9990
deployDir: options.deployDir);
10091
}

packages/flutter_build/lib/src/app_build.dart

+28-8
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,23 @@ enum FlutterWebRenderer {
2525

2626
/// Build options.
2727
class FlutterWebAppBuildOptions {
28+
/// Target
29+
///
30+
/// The main entry-point file of the application, as run on the device.
31+
/// If the "--target" option is omitted, but a file name is provided on the command line, then that is used
32+
/// instead.
33+
///
34+
/// (defaults to "lib/main.dart")
35+
final String? target;
36+
2837
/// Renderer
29-
FlutterWebRenderer? renderer;
38+
final FlutterWebRenderer? renderer;
3039

3140
/// Compile as wasm
32-
bool? wasm;
41+
final bool? wasm;
3342

3443
/// Build options.
35-
FlutterWebAppBuildOptions({this.renderer, this.wasm});
44+
FlutterWebAppBuildOptions({this.renderer, this.wasm, this.target});
3645
}
3746

3847
/// Web app options
@@ -111,16 +120,23 @@ class FlutterWebAppBuilder implements CommonAppBuilder {
111120
deployer: deployer);
112121
}
113122

114-
Shell get _shell => controller?.shell ?? Shell();
123+
Shell get _shell => controller?.shell ?? Shell(workingDirectory: path);
115124

116125
/// Build
117126
Future<void> build() async {
127+
await buildOnly();
128+
await _webAppBuildToDeploy();
129+
}
130+
131+
/// Build
132+
Future<void> buildOnly() async {
133+
var buildOptions = options.buildOptions;
118134
var shell = _shell;
119135
var renderOptions = '';
120-
var wasm = options.buildOptions?.wasm ?? false;
136+
var wasm = buildOptions?.wasm ?? false;
121137
if (!wasm) {
122138
// not compatible with wasm
123-
switch (options.buildOptions?.renderer) {
139+
switch (buildOptions?.renderer) {
124140
case FlutterWebRenderer.html:
125141
renderOptions = ' --web-renderer html';
126142
break;
@@ -131,8 +147,12 @@ class FlutterWebAppBuilder implements CommonAppBuilder {
131147
}
132148
}
133149
var wasmOptions = wasm ? ' --wasm' : '';
134-
await shell.run('flutter build web$renderOptions$wasmOptions');
135-
await _webAppBuildToDeploy();
150+
var targetOptions = '';
151+
if (buildOptions?.target != null) {
152+
targetOptions = ' --target ${buildOptions!.target}';
153+
}
154+
await shell
155+
.run('flutter build web$renderOptions$wasmOptions$targetOptions');
136156
}
137157

138158
/// Copy to deploy using deploy.yaml

0 commit comments

Comments
 (0)