Skip to content

Conversation

@micaelcid
Copy link
Contributor

@micaelcid micaelcid commented Jul 4, 2025

Closes #171637

As mentioned in the issue, I am proposing a new argument to the flutter build web command: --static-assets-url.

This argument would accept a full URL string ending with / as its value. During the build process, the Flutter tool would use this value to replace a dedicated placeholder within the web/index.html file (inspired by --base-href approach).

Example Implementation:

A developer would modify their web/index.html to use a new placeholder, for instance, $FLUTTER_STATIC_ASSETS_URL:

...
<body>
  <script>
    {{flutter_js}}
    {{flutter_build_config}}

    _flutter.loader.load({
      config: {
        entryPointBaseUrl: "$FLUTTER_STATIC_ASSETS_URL",
      },
      onEntrypointLoaded: async function (engineInitializer) {
        const appRunner = await engineInitializer.initializeEngine({
          assetBase: "$FLUTTER_STATIC_ASSETS_URL",
        });

        await appRunner.runApp();
      },
    });
  </script>
</body>
...

The build command would be run with the new flag: flutter build web --static-assets-url="https://static.company.com/some-webapp/“ - and the resulting build/web/index.html would have the placeholder replaced:

...
<body>
  <script>
    {{flutter_js}}
    {{flutter_build_config}}

    _flutter.loader.load({
      config: {
        entryPointBaseUrl: "https://static.company.com/some-webapp/",
      },
      onEntrypointLoaded: async function (engineInitializer) {
        const appRunner = await engineInitializer.initializeEngine({
          assetBase: "https://static.company.com/some-webapp/",
        });

        await appRunner.runApp();
      },
    });
  </script>
</body>
...

@github-actions github-actions bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jul 4, 2025
@micaelcid micaelcid changed the title feat: add --static-assets-url argument to build web [web] add --static-assets-url argument to build web Jul 4, 2025
@micaelcid micaelcid marked this pull request as draft July 4, 2025 16:28
@flutter-dashboard
Copy link

This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@micaelcid micaelcid marked this pull request as ready for review July 5, 2025 20:05
@micaelcid micaelcid marked this pull request as draft July 5, 2025 20:17
@micaelcid micaelcid marked this pull request as ready for review July 5, 2025 22:10
@mdebbar mdebbar added the platform-web Web applications specifically label Jul 16, 2025
@mdebbar mdebbar requested a review from harryterkelsen July 16, 2025 18:29
@micaelcid
Copy link
Contributor Author

Hey @harryterkelsen can you review this one? :)

Copy link
Contributor

@harryterkelsen harryterkelsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM with one requested change

'static-assets-url',
help:
'Used when serving the static assets from a different domain the application is hosted on. '
'The value has to start with http and end with a slash "/". '
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having the static assets url start with http is a little too restrictive and also this documentation is somewhat ambiguous (can the --static-assets-url point to an https:// URL? Yes, but a reasonable person could read this documentation and think only http:// is allowed). I think just remove the check for startsWith('http'), keep the check for endsWith('/'), and update the documentation accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, @harryterkelsen. Thanks for your review! I just added a commit attending to your request.

@harryterkelsen
Copy link
Contributor

Sorry for letting this drop off my radar! Thanks for your PR, I requested a small change

@github-actions github-actions bot removed the platform-web Web applications specifically label Jul 25, 2025
@micaelcid
Copy link
Contributor Author

micaelcid commented Aug 6, 2025

Hello @harryterkelsen, sorry for pinging twice in a row. Do you mind reviewing this again?

Copy link
Contributor

@harryterkelsen harryterkelsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nit

@harryterkelsen harryterkelsen added this pull request to the merge queue Aug 7, 2025
Merged via the queue into flutter:master with commit 3be0441 Aug 7, 2025
141 checks passed
houssemeddinefadhli81 pushed a commit to houssemeddinefadhli81/flutter that referenced this pull request Aug 7, 2025
Closes flutter#171637

As mentioned in the issue, I am proposing a new argument to the flutter
build web command: `--static-assets-url`.

This argument would accept a full URL string ending with `/` as its
value. During the build process, the Flutter tool would use this value
to replace a dedicated placeholder within the `web/index.html` file
(inspired by `--base-href` approach).

Example Implementation:

A developer would modify their `web/index.html` to use a new
placeholder, for instance, `$FLUTTER_STATIC_ASSETS_URL`:

```html
...
<body>
  <script>
    {{flutter_js}}
    {{flutter_build_config}}

    _flutter.loader.load({
      config: {
        entryPointBaseUrl: "$FLUTTER_STATIC_ASSETS_URL",
      },
      onEntrypointLoaded: async function (engineInitializer) {
        const appRunner = await engineInitializer.initializeEngine({
          assetBase: "$FLUTTER_STATIC_ASSETS_URL",
        });

        await appRunner.runApp();
      },
    });
  </script>
</body>
...
 ```

The build command would be run with the new flag: `flutter build web --static-assets-url="https://static.company.com/some-webapp/“` - and the resulting `build/web/index.html` would have the placeholder replaced: 

```html
...
<body>
  <script>
    {{flutter_js}}
    {{flutter_build_config}}

    _flutter.loader.load({
      config: {
        entryPointBaseUrl: "https://static.company.com/some-webapp/",
      },
      onEntrypointLoaded: async function (engineInitializer) {
        const appRunner = await engineInitializer.initializeEngine({
          assetBase: "https://static.company.com/some-webapp/",
        });

        await appRunner.runApp();
      },
    });
  </script>
</body>
...
```
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 8, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 8, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 8, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Aug 8, 2025
flutter/flutter@92a6bfb...3821790

2025-08-08 [email protected] Use LLDB as the default debugging method for iOS 17+ and Xcode 26+ (flutter/flutter#173443)
2025-08-08 [email protected] Roll Fuchsia Linux SDK from i4vsuEGyP8Xeb5tiy... to HclTm0V8hgSpfqmtG... (flutter/flutter#173462)
2025-08-08 [email protected] Support launching a HTTPS URL (flutter/flutter#164720)
2025-08-08 [email protected] Roll Dart SDK from c48772a79e1f to 4b7b565eb468 (1 revision) (flutter/flutter#173454)
2025-08-08 [email protected] Roll Dart SDK from ba58b96a80d7 to c48772a79e1f (3 revisions) (flutter/flutter#173451)
2025-08-07 [email protected] Web dev proxy (flutter/flutter#172175)
2025-08-07 [email protected] Roll ICU from b929596baebf to 1b2e3e8a421e (7 revisions) (flutter/flutter#173436)
2025-08-07 [email protected] [A11y] TextField prefix icon and suffix icon create a sibling node' (flutter/flutter#173312)
2025-08-07 [email protected] [Android templates] Remove jetifier usage (flutter/flutter#173431)
2025-08-07 [email protected] Remove a couple of asserts from display_list_unittest (flutter/flutter#173381)
2025-08-07 [email protected] Fix ScaffoldGeometry null scale with noAnimation FAB (flutter/flutter#172914)
2025-08-07 [email protected] Prepare for iOS debugging with lldb and devicectl (flutter/flutter#173417)
2025-08-07 [email protected] Fix `ReorderableList` proxy animation for partial drag-back (flutter/flutter#172380)
2025-08-07 [email protected] [ios26]Do not report error for Info.plist key not found (flutter/flutter#172913)
2025-08-07 [email protected] Manual roll to 3.10.0-75.1.beta (flutter/flutter#173423)
2025-08-07 [email protected] [web] add --static-assets-url argument to build web (flutter/flutter#171638)
2025-08-07 [email protected] Adds deprecation for impeller opt out on android (flutter/flutter#173375)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
ksokolovskyi pushed a commit to ksokolovskyi/flutter that referenced this pull request Aug 19, 2025
Closes flutter#171637

As mentioned in the issue, I am proposing a new argument to the flutter
build web command: `--static-assets-url`.

This argument would accept a full URL string ending with `/` as its
value. During the build process, the Flutter tool would use this value
to replace a dedicated placeholder within the `web/index.html` file
(inspired by `--base-href` approach).

Example Implementation:

A developer would modify their `web/index.html` to use a new
placeholder, for instance, `$FLUTTER_STATIC_ASSETS_URL`:

```html
...
<body>
  <script>
    {{flutter_js}}
    {{flutter_build_config}}

    _flutter.loader.load({
      config: {
        entryPointBaseUrl: "$FLUTTER_STATIC_ASSETS_URL",
      },
      onEntrypointLoaded: async function (engineInitializer) {
        const appRunner = await engineInitializer.initializeEngine({
          assetBase: "$FLUTTER_STATIC_ASSETS_URL",
        });

        await appRunner.runApp();
      },
    });
  </script>
</body>
...
 ```

The build command would be run with the new flag: `flutter build web --static-assets-url="https://static.company.com/some-webapp/“` - and the resulting `build/web/index.html` would have the placeholder replaced: 

```html
...
<body>
  <script>
    {{flutter_js}}
    {{flutter_build_config}}

    _flutter.loader.load({
      config: {
        entryPointBaseUrl: "https://static.company.com/some-webapp/",
      },
      onEntrypointLoaded: async function (engineInitializer) {
        const appRunner = await engineInitializer.initializeEngine({
          assetBase: "https://static.company.com/some-webapp/",
        });

        await appRunner.runApp();
      },
    });
  </script>
</body>
...
```
mboetger pushed a commit to mboetger/flutter that referenced this pull request Sep 18, 2025
Closes flutter#171637

As mentioned in the issue, I am proposing a new argument to the flutter
build web command: `--static-assets-url`.

This argument would accept a full URL string ending with `/` as its
value. During the build process, the Flutter tool would use this value
to replace a dedicated placeholder within the `web/index.html` file
(inspired by `--base-href` approach).

Example Implementation:

A developer would modify their `web/index.html` to use a new
placeholder, for instance, `$FLUTTER_STATIC_ASSETS_URL`:

```html
...
<body>
  <script>
    {{flutter_js}}
    {{flutter_build_config}}

    _flutter.loader.load({
      config: {
        entryPointBaseUrl: "$FLUTTER_STATIC_ASSETS_URL",
      },
      onEntrypointLoaded: async function (engineInitializer) {
        const appRunner = await engineInitializer.initializeEngine({
          assetBase: "$FLUTTER_STATIC_ASSETS_URL",
        });

        await appRunner.runApp();
      },
    });
  </script>
</body>
...
 ```

The build command would be run with the new flag: `flutter build web --static-assets-url="https://static.company.com/some-webapp/“` - and the resulting `build/web/index.html` would have the placeholder replaced: 

```html
...
<body>
  <script>
    {{flutter_js}}
    {{flutter_build_config}}

    _flutter.loader.load({
      config: {
        entryPointBaseUrl: "https://static.company.com/some-webapp/",
      },
      onEntrypointLoaded: async function (engineInitializer) {
        const appRunner = await engineInitializer.initializeEngine({
          assetBase: "https://static.company.com/some-webapp/",
        });

        await appRunner.runApp();
      },
    });
  </script>
</body>
...
```
korca0220 pushed a commit to korca0220/flutter that referenced this pull request Sep 22, 2025
Closes flutter#171637

As mentioned in the issue, I am proposing a new argument to the flutter
build web command: `--static-assets-url`.

This argument would accept a full URL string ending with `/` as its
value. During the build process, the Flutter tool would use this value
to replace a dedicated placeholder within the `web/index.html` file
(inspired by `--base-href` approach).

Example Implementation:

A developer would modify their `web/index.html` to use a new
placeholder, for instance, `$FLUTTER_STATIC_ASSETS_URL`:

```html
...
<body>
  <script>
    {{flutter_js}}
    {{flutter_build_config}}

    _flutter.loader.load({
      config: {
        entryPointBaseUrl: "$FLUTTER_STATIC_ASSETS_URL",
      },
      onEntrypointLoaded: async function (engineInitializer) {
        const appRunner = await engineInitializer.initializeEngine({
          assetBase: "$FLUTTER_STATIC_ASSETS_URL",
        });

        await appRunner.runApp();
      },
    });
  </script>
</body>
...
 ```

The build command would be run with the new flag: `flutter build web --static-assets-url="https://static.company.com/some-webapp/“` - and the resulting `build/web/index.html` would have the placeholder replaced: 

```html
...
<body>
  <script>
    {{flutter_js}}
    {{flutter_build_config}}

    _flutter.loader.load({
      config: {
        entryPointBaseUrl: "https://static.company.com/some-webapp/",
      },
      onEntrypointLoaded: async function (engineInitializer) {
        const appRunner = await engineInitializer.initializeEngine({
          assetBase: "https://static.company.com/some-webapp/",
        });

        await appRunner.runApp();
      },
    });
  </script>
</body>
...
```
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 12, 2025
lucaantonelli pushed a commit to lucaantonelli/flutter that referenced this pull request Nov 21, 2025
Closes flutter#171637

As mentioned in the issue, I am proposing a new argument to the flutter
build web command: `--static-assets-url`.

This argument would accept a full URL string ending with `/` as its
value. During the build process, the Flutter tool would use this value
to replace a dedicated placeholder within the `web/index.html` file
(inspired by `--base-href` approach).

Example Implementation:

A developer would modify their `web/index.html` to use a new
placeholder, for instance, `$FLUTTER_STATIC_ASSETS_URL`:

```html
...
<body>
  <script>
    {{flutter_js}}
    {{flutter_build_config}}

    _flutter.loader.load({
      config: {
        entryPointBaseUrl: "$FLUTTER_STATIC_ASSETS_URL",
      },
      onEntrypointLoaded: async function (engineInitializer) {
        const appRunner = await engineInitializer.initializeEngine({
          assetBase: "$FLUTTER_STATIC_ASSETS_URL",
        });

        await appRunner.runApp();
      },
    });
  </script>
</body>
...
 ```

The build command would be run with the new flag: `flutter build web --static-assets-url="https://static.company.com/some-webapp/“` - and the resulting `build/web/index.html` would have the placeholder replaced: 

```html
...
<body>
  <script>
    {{flutter_js}}
    {{flutter_build_config}}

    _flutter.loader.load({
      config: {
        entryPointBaseUrl: "https://static.company.com/some-webapp/",
      },
      onEntrypointLoaded: async function (engineInitializer) {
        const appRunner = await engineInitializer.initializeEngine({
          assetBase: "https://static.company.com/some-webapp/",
        });

        await appRunner.runApp();
      },
    });
  </script>
</body>
...
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[web] add --static-assets-url argument to build web command

3 participants