Injecting base href into service worker
diff --git a/packages/flutter_tools/lib/src/build_system/targets/web.dart b/packages/flutter_tools/lib/src/build_system/targets/web.dart
index 1398ae8..9610ab5 100644
--- a/packages/flutter_tools/lib/src/build_system/targets/web.dart
+++ b/packages/flutter_tools/lib/src/build_system/targets/web.dart
@@ -392,6 +392,8 @@
     'flutter_assets.d',
     'web_resources.d',
   ];
+  
+  String get baseHref => environment.defines[kBaseHref] ?? '/';
 
   bool shouldCopy(String name) =>
       // Do not copy the deps file.
@@ -456,7 +458,7 @@
       if (environment.fileSystem.path.basename(inputFile.path) == 'index.html') {
         final IndexHtml indexHtml = IndexHtml(inputFile.readAsStringSync());
         indexHtml.applySubstitutions(
-          baseHref: environment.defines[kBaseHref] ?? '/',
+          baseHref: baseHref,
           serviceWorkerVersion: Random().nextInt(4294967296).toString(),
         );
         outputFile.writeAsStringSync(indexHtml.content);
@@ -624,6 +626,7 @@
           'assets/FontManifest.json',
       ],
       serviceWorkerStrategy: serviceWorkerStrategy,
+      baseHref: baseHref,
     );
     serviceWorkerFile
       .writeAsStringSync(serviceWorker);
diff --git a/packages/flutter_tools/lib/src/web/file_generators/flutter_service_worker_js.dart b/packages/flutter_tools/lib/src/web/file_generators/flutter_service_worker_js.dart
index 24ce814..e849a08 100644
--- a/packages/flutter_tools/lib/src/web/file_generators/flutter_service_worker_js.dart
+++ b/packages/flutter_tools/lib/src/web/file_generators/flutter_service_worker_js.dart
@@ -25,6 +25,7 @@
   Map<String, String> resources,
   List<String> coreBundle, {
   required ServiceWorkerStrategy serviceWorkerStrategy,
+  required String baseHref,
 }) {
   if (serviceWorkerStrategy == ServiceWorkerStrategy.none) {
     return '';
@@ -38,6 +39,7 @@
   return globals.localFileSystem
       .file(flutterServiceWorkerJsPath)
       .readAsStringSync()
+      .replaceAll(r'$$BASE_HREF', '"$baseHref"'),
       .replaceAll(
         r'$$RESOURCES_MAP',
         '{${resources.entries.map((MapEntry<String, String> entry) => '"${entry.key}": "${entry.value}"').join(",\n")}}',
diff --git a/packages/flutter_tools/lib/src/web/file_generators/js/flutter_service_worker.js b/packages/flutter_tools/lib/src/web/file_generators/js/flutter_service_worker.js
index 7a5b124..481a541 100644
--- a/packages/flutter_tools/lib/src/web/file_generators/js/flutter_service_worker.js
+++ b/packages/flutter_tools/lib/src/web/file_generators/js/flutter_service_worker.js
@@ -3,6 +3,7 @@
 const TEMP = 'flutter-temp-cache';
 const CACHE_NAME = 'flutter-app-cache';
 
+const BASE_HREF = $$BASE_HREF;
 const RESOURCES = $$RESOURCES_MAP;
 // The application shell files that are downloaded before a service worker can
 // start.