1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 13:58:47 +00:00
Files
samples/web_embedding/ng-flutter
dependabot[bot] a7e5af5c5f Bump @angular/cli from 18.0.7 to 18.1.0 in /web_embedding/ng-flutter (#2357)
Bumps [@angular/cli](https://github.com/angular/angular-cli) from 18.0.7
to 18.1.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/angular/angular-cli/releases"><code>@​angular/cli</code>'s
releases</a>.</em></p>
<blockquote>
<h2>v18.1.0</h2>
<p><!-- raw HTML omitted --><!-- raw HTML omitted --></p>
<h1>18.1.0 (2024-07-10)</h1>
<h3><code>@​schematics/angular</code></h3>
<table>
<thead>
<tr>
<th>Commit</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a
href="22e05dcb4a"><img
src="https://img.shields.io/badge/22e05dcb4-fix-green" alt="fix -
22e05dcb4" /></a></td>
<td>generate new projects with ECMAScript standard class field
behavior</td>
</tr>
</tbody>
</table>
<h3><code>@​angular/cli</code></h3>
<table>
<thead>
<tr>
<th>Commit</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a
href="6d266c146c"><img
src="https://img.shields.io/badge/6d266c146-fix-green" alt="fix -
6d266c146" /></a></td>
<td>add fallbacks for migration package resolution</td>
</tr>
</tbody>
</table>
<h3><code>@​angular/build</code></h3>
<table>
<thead>
<tr>
<th>Commit</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a
href="687a6c7eca"><img
src="https://img.shields.io/badge/687a6c7ec-feat-blue" alt="feat -
687a6c7ec" /></a></td>
<td>add <code>--inspect</code> option to the dev-server</td>
</tr>
<tr>
<td><a
href="628d87a947"><img
src="https://img.shields.io/badge/628d87a94-feat-blue" alt="feat -
628d87a94" /></a></td>
<td>support WASM/ES Module integration proposal</td>
</tr>
<tr>
<td><a
href="3e359da8df"><img
src="https://img.shields.io/badge/3e359da8d-fix-green" alt="fix -
3e359da8d" /></a></td>
<td>address rxjs undefined issues during SSR prebundling</td>
</tr>
<tr>
<td><a
href="4ff914a165"><img
src="https://img.shields.io/badge/4ff914a16-fix-green" alt="fix -
4ff914a16" /></a></td>
<td>allow additional module preloads up to limit</td>
</tr>
<tr>
<td><a
href="fb8e3c39a8"><img
src="https://img.shields.io/badge/fb8e3c39a-fix-green" alt="fix -
fb8e3c39a" /></a></td>
<td>allow top-level await in zoneless applications</td>
</tr>
<tr>
<td><a
href="83b75af9f7"><img
src="https://img.shields.io/badge/83b75af9f-fix-green" alt="fix -
83b75af9f" /></a></td>
<td>check inlineSourceMap option with isolated modules optimization</td>
</tr>
<tr>
<td><a
href="cd97134a6e"><img
src="https://img.shields.io/badge/cd97134a6-fix-green" alt="fix -
cd97134a6" /></a></td>
<td>normalize paths during module resolution in Vite</td>
</tr>
<tr>
<td><a
href="13d2100ddc"><img
src="https://img.shields.io/badge/13d2100dd-fix-green" alt="fix -
13d2100dd" /></a></td>
<td>read WASM file from script location on Node.js</td>
</tr>
<tr>
<td><a
href="3091956f50"><img
src="https://img.shields.io/badge/3091956f5-fix-green" alt="fix -
3091956f5" /></a></td>
<td>support import attributes in JavaScript transformer</td>
</tr>
<tr>
<td><a
href="dd94a831b4"><img
src="https://img.shields.io/badge/dd94a831b-perf-orange" alt="perf -
dd94a831b" /></a></td>
<td>enable dependency prebundling for server dependencies</td>
</tr>
<tr>
<td><a
href="3acb776831"><img
src="https://img.shields.io/badge/3acb77683-perf-orange" alt="perf -
3acb77683" /></a></td>
<td>use direct transpilation with isolated modules</td>
</tr>
</tbody>
</table>
<h2>v18.1.0-rc.1</h2>
<p><!-- raw HTML omitted --><!-- raw HTML omitted --></p>
<h1>18.1.0-rc.1 (2024-07-03)</h1>
<h3><code>@​angular/cli</code></h3>
<table>
<thead>
<tr>
<th>Commit</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a
href="6c0f60d1bd"><img
src="https://img.shields.io/badge/6c0f60d1b-fix-green" alt="fix -
6c0f60d1b" /></a></td>
<td>make <code>ng update</code> to keep newline at the end of
package.json</td>
</tr>
</tbody>
</table>
<h3><code>@​angular-devkit/build-angular</code></h3>
<table>
<thead>
<tr>
<th>Commit</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a
href="1eb36e5938"><img
src="https://img.shields.io/badge/1eb36e593-fix-green" alt="fix -
1eb36e593" /></a></td>
<td>reduce the number of max workers to available CPUs minus one</td>
</tr>
<tr>
<td><a
href="c6fc0203e0"><img
src="https://img.shields.io/badge/c6fc0203e-fix-green" alt="fix -
c6fc0203e" /></a></td>
<td>rollback terser to <code>5.29.2</code></td>
</tr>
</tbody>
</table>
<h3><code>@​angular/build</code></h3>
<table>
<thead>
<tr>
<th>Commit</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a
href="628d87a947"><img
src="https://img.shields.io/badge/628d87a94-feat-blue" alt="feat -
628d87a94" /></a></td>
<td>support WASM/ES Module integration proposal</td>
</tr>
<tr>
<td><a
href="fb8e3c39a8"><img
src="https://img.shields.io/badge/fb8e3c39a-fix-green" alt="fix -
fb8e3c39a" /></a></td>
<td>allow top-level await in zoneless applications</td>
</tr>
<tr>
<td><a
href="5ec7243385"><img
src="https://img.shields.io/badge/5ec724338-fix-green" alt="fix -
5ec724338" /></a></td>
<td>correctly name entry points to match budgets</td>
</tr>
<tr>
<td><a
href="cd97134a6e"><img
src="https://img.shields.io/badge/cd97134a6-fix-green" alt="fix -
cd97134a6" /></a></td>
<td>normalize paths during module resolution in Vite</td>
</tr>
<tr>
<td><a
href="27bd670831"><img
src="https://img.shields.io/badge/27bd67083-fix-green" alt="fix -
27bd67083" /></a></td>
<td>redirect to path with trailing slash for asset directories</td>
</tr>
<tr>
<td><a
href="e8a6d6bc41"><img
src="https://img.shields.io/badge/e8a6d6bc4-fix-green" alt="fix -
e8a6d6bc4" /></a></td>
<td>reduce the number of max workers to available CPUs minus one</td>
</tr>
<tr>
<td><a
href="3091956f50"><img
src="https://img.shields.io/badge/3091956f5-fix-green" alt="fix -
3091956f5" /></a></td>
<td>support import attributes in JavaScript transformer</td>
</tr>
</tbody>
</table>
<h2>v18.1.0-rc.0</h2>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/angular/angular-cli/blob/main/CHANGELOG.md"><code>@​angular/cli</code>'s
changelog</a>.</em></p>
<blockquote>
<h1>18.1.0 (2024-07-10)</h1>
<h3><code>@​angular/cli</code></h3>
<table>
<thead>
<tr>
<th>Commit</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a
href="6d266c146c">6d266c146</a></td>
<td>fix</td>
<td>add fallbacks for migration package resolution</td>
</tr>
</tbody>
</table>
<h3><code>@​schematics/angular</code></h3>
<table>
<thead>
<tr>
<th>Commit</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a
href="22e05dcb4a">22e05dcb4</a></td>
<td>fix</td>
<td>generate new projects with ECMAScript standard class field
behavior</td>
</tr>
</tbody>
</table>
<h3><code>@​angular/build</code></h3>
<table>
<thead>
<tr>
<th>Commit</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a
href="687a6c7eca">687a6c7ec</a></td>
<td>feat</td>
<td>add <code>--inspect</code> option to the dev-server</td>
</tr>
<tr>
<td><a
href="628d87a947">628d87a94</a></td>
<td>feat</td>
<td>support WASM/ES Module integration proposal</td>
</tr>
<tr>
<td><a
href="3e359da8df">3e359da8d</a></td>
<td>fix</td>
<td>address rxjs undefined issues during SSR prebundling</td>
</tr>
<tr>
<td><a
href="4ff914a165">4ff914a16</a></td>
<td>fix</td>
<td>allow additional module preloads up to limit</td>
</tr>
<tr>
<td><a
href="fb8e3c39a8">fb8e3c39a</a></td>
<td>fix</td>
<td>allow top-level await in zoneless applications</td>
</tr>
<tr>
<td><a
href="83b75af9f7">83b75af9f</a></td>
<td>fix</td>
<td>check inlineSourceMap option with isolated modules optimization</td>
</tr>
<tr>
<td><a
href="cd97134a6e">cd97134a6</a></td>
<td>fix</td>
<td>normalize paths during module resolution in Vite</td>
</tr>
<tr>
<td><a
href="13d2100ddc">13d2100dd</a></td>
<td>fix</td>
<td>read WASM file from script location on Node.js</td>
</tr>
<tr>
<td><a
href="3091956f50">3091956f5</a></td>
<td>fix</td>
<td>support import attributes in JavaScript transformer</td>
</tr>
<tr>
<td><a
href="dd94a831b4">dd94a831b</a></td>
<td>perf</td>
<td>enable dependency prebundling for server dependencies</td>
</tr>
<tr>
<td><a
href="3acb776831">3acb77683</a></td>
<td>perf</td>
<td>use direct transpilation with isolated modules</td>
</tr>
</tbody>
</table>
<!-- raw HTML omitted -->
<p><!-- raw HTML omitted --><!-- raw HTML omitted --></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="482d0bea35"><code>482d0be</code></a>
release: cut the v18.1.0 release</li>
<li><a
href="0c52d5f807"><code>0c52d5f</code></a>
build: update Angular dependencies to version 18.1.0</li>
<li><a
href="13d2100ddc"><code>13d2100</code></a>
fix(<code>@​angular/build</code>): read WASM file from script location
on Node.js</li>
<li><a
href="1772c871ba"><code>1772c87</code></a>
refactor(<code>@​angular/cli</code>): provide a default extract-i18n
target for applications</li>
<li><a
href="4c6c32c439"><code>4c6c32c</code></a>
refactor: use explicit coercion of exitCode to number.</li>
<li><a
href="83b75af9f7"><code>83b75af</code></a>
fix(<code>@​angular/build</code>): check inlineSourceMap option with
isolated modules optim...</li>
<li><a
href="713f456a27"><code>713f456</code></a>
release: cut the v18.1.0-rc.1 release</li>
<li><a
href="628d87a947"><code>628d87a</code></a>
feat(<code>@​angular/build</code>): support WASM/ES Module integration
proposal</li>
<li><a
href="3091956f50"><code>3091956</code></a>
fix(<code>@​angular/build</code>): support import attributes in
JavaScript transformer</li>
<li><a
href="c6fc0203e0"><code>c6fc020</code></a>
fix(<code>@​angular-devkit/build-angular</code>): rollback terser to
<code>5.29.2</code></li>
<li>Additional commits viewable in <a
href="https://github.com/angular/angular-cli/compare/18.0.7...18.1.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=@angular/cli&package-manager=npm_and_yarn&previous-version=18.0.7&new-version=18.1.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-07-16 12:23:24 +10:00
..
2023-05-06 10:53:17 +10:00

ng-flutter

This Angular project is a simple example of how Angular and Flutter web apps could be integrated, and have them interop.

Points of Interest

Angular

This repository is a quite standard Angular app. The following changes were made to be able to use (and interop) with a Flutter web application:

  • package.json has a custom prebuild script that builds the Flutter web app, so Angular can find it later.
  • flutter.js is added as a "scripts" entry in angular.json. Angular takes care of minimizing and injecting it as any other script.
  • The rest of the flutter app flutter/build/web/ is registered as an "assets" entry in angular.json, and moved to /flutter.
  • The ng-flutter component takes care of embedding Flutter web, and yielding control to Angular through an appLoaded EventEmitter. The object yielded by this emitter is a state controller exposed by flutter via a JS custom event!

Flutter

The embedded Flutter application lives in the flutter directory of this repo. That application is a standard web app, that doesn't need to be aware that it's going to be embedded in another framework.

  • Flutter uses new @staticInterop methods to allow certain Dart functions to be called from JavaScript.
  • Look at how createDartExport and broadcastAppEvent work together to make the _state controller of the Flutter app available to Angular!

How to build the app

Requirements

If you want to build and run this demo on your machine, you'll need a moderately recent version of Angular:

$ ng version

Angular CLI: 17.0.0
Node: 20.9.0
Package Manager: npm 10.1.0
OS: linux x64

And Flutter:

$ flutter --version

Flutter 3.13.9 • channel stable
Framework • revision d211f42860 (2 weeks ago) • 2023-10-25 13:42:25 -0700
Engine • revision 0545f8705d
Tools • Dart 3.1.5 • DevTools 2.25.0

Ensure npm, ng and flutter are present in your $PATH.

Building the app

This repository is a moderately standard Angular app. It integrates Flutter web by making it part of the Angular assets.

In order to build this app, first fetch its npm dependencies:

$ npm install

added 963 packages, and audited 964 packages in 17s

93 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Then run the build script. It'll take care of building Flutter automatically:

$ npm run build

> ng-flutter@0.0.0 prebuild

... Flutter web build output ...

Compiling lib/main.dart for the Web...

> ng-flutter@0.0.0 build
> ng build

... Angular build output ...

✔ Browser application bundle generation complete.
✔ Copying assets complete.
✔ Index html generation complete.

Local Angular development

Once you've reached this point, you should be able to work with your Angular application normally, for example to run a local web server:

$ npm run start

> ng-flutter@0.0.0 start
> ng serve

✔ Browser application bundle generation complete.

Initial Chunk Files   | Names         |  Raw Size
vendor.js             | vendor        |   4.38 MB | 

... Angular build output...

** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **


✔ Compiled successfully.

Navigate to http://localhost:4200/. The application will automatically reload if you change any of its Angular source files.

Local Flutter web development

The Flutter app lives inside the flutter directory, and can be developed independently. Just do any changes on Flutter web as you'd normally do. It even includes a small web/index.html so you can see changes to your app without running the whole Angular setup.

Note

For now, Angular does not auto-detect changes to your Flutter web app, so once you're happy with your Flutter web app, make sure to call npm run build so everything rebuilds and gets placed into its correct location.

Deploying the app

After npm run build, you should have a deployable Angular + Flutter web app in the dist directory of this Angular project.

Your built app can can be deployed anywhere, but do check Firebase hosting for a super-easy deployment experience!

Troubleshooting

Flutter

Ensure your flutter app is properly rebuilt after any changes.

  • Run npm run build to re-build the Flutter app.

If you encounter error messages like:

Error: Can't resolve 'flutter/build/web/flutter.js' in '/my/checkout/of/ng-flutter'

You definitely need to run npm run build!

Reach out to the team(s)!

Have you had any problem not covered in this README? Do you want to see other embedding examples?

Let us know by creating an issue or opening a new pull request.

Thanks!