Skip to content

Commit

Permalink
Support build wasm (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
nploi authored Aug 13, 2024
1 parent 8d7541b commit 2e8423a
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.1.0

- Support build wasm option for Flutter web.

## 5.0.1-wip

- Require Dart 3.0
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Arguments:
[html] This renderer uses a combination of HTML, CSS,
SVG, 2D Canvas, and WebGL.

--[no-]wasm Whether to build for WebAssembly (WASM).
--extra-args Extra arguments to provide to the target CLI
within a single string.
Examples:
Expand Down
8 changes: 6 additions & 2 deletions lib/src/flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ Future<void> runFlutterBuild(
final args = <String>[
'build',
'web',
'--web-renderer',
options.webRendererString(),
if (options.wasm)
'--wasm'
else ...[
'--web-renderer',
options.webRendererString(),
],
options.release ? '--release' : '--profile',
...?options.splitExtraArgs()
];
Expand Down
7 changes: 7 additions & 0 deletions lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ See the README for details.''',
@JsonKey(includeToJson: false, includeFromJson: false)
final bool webRendererWasParsed;

@CliOption(
help: 'Whether to build for WebAssembly (WASM).',
)
final bool wasm;

String webRendererString() => _$WebRendererEnumMap[webRenderer]!;

@CliOption(
Expand Down Expand Up @@ -210,6 +215,7 @@ See the README for details.''',
this.dryRun = _defaultDryRun,
this.webRenderer = _defaultWebRenderer,
this.webRendererWasParsed = false,
this.wasm = false,
this.extraArgsWasParsed = false,
this.extraArgs,
this.help = false,
Expand All @@ -235,6 +241,7 @@ See the README for details.''',
dryRun: dryRun,
extraArgs: extraArgsWasParsed ? extraArgs : other.extraArgs,
webRenderer: webRendererWasParsed ? webRenderer : other.webRenderer,
wasm: wasm,
help: help,
message: messageWasParsed ? message : other.message,
postBuildDartScript: postBuildDartScriptWasParsed
Expand Down
8 changes: 8 additions & 0 deletions lib/src/options.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: peanut
version: 5.0.1-wip
version: 5.1.0
description: >-
Update your GitHub gh-pages branch with the compiled output of your Dart web
app. Supports 'pub build' and the new 'pub run build_runner'.
Expand Down
1 change: 1 addition & 0 deletions test/cli_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Arguments:
[html] This renderer uses a combination of HTML, CSS,
SVG, 2D Canvas, and WebGL.
--[no-]wasm Whether to build for WebAssembly (WASM).
--extra-args Extra arguments to provide to the target CLI
within a single string.
Examples:
Expand Down
2 changes: 2 additions & 0 deletions test/options_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void main() {
'release': false,
'verbose': true,
'source-branch-info': false,
'wasm': false
});
_checkDefault(
allFileOptions,
Expand Down Expand Up @@ -132,6 +133,7 @@ void _checkDefault(
expect(options.sourceBranchInfoWasParsed, wasParsed);
expect(options.verbose, expected.verbose);
expect(options.verboseWasParsed, wasParsed);
expect(options.wasm, expected.wasm);

expect(options.version, jsonSkippedDefault ?? expected.version);
}

0 comments on commit 2e8423a

Please sign in to comment.