From 6a0985c32151b52bfe25335118a9ddeecaa0c118 Mon Sep 17 00:00:00 2001
From: Samuel Meuli <meuli@adobe.com>
Date: Tue, 24 Sep 2019 09:08:08 +0200
Subject: [PATCH] Add "entrypoints" key to asset manifest

---
 packages/react-scripts/config/webpack.config.js | 17 ++++++++++++-----
 packages/react-scripts/package.json             |  2 +-
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js
index f88910d4dbe..fa55b6172a5 100644
--- a/packages/react-scripts/config/webpack.config.js
+++ b/packages/react-scripts/config/webpack.config.js
@@ -631,20 +631,27 @@ module.exports = function(webpackEnv) {
           filename: 'static/css/[name].[contenthash:8].css',
           chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
         }),
-      // Generate a manifest file which contains a mapping of all asset filenames
-      // to their corresponding output file so that tools can pick it up without
-      // having to parse `index.html`.
+      // Generate an asset manifest file with the following content:
+      // - "files" key: Mapping of all asset filenames to their corresponding
+      //   output file so that tools can pick it up without having to parse
+      //   `index.html`
+      // - "entrypoints" key: Array of files which are included in `index.html`,
+      //   can be used to reconstruct the HTML if necessary
       new ManifestPlugin({
         fileName: 'asset-manifest.json',
         publicPath: publicPath,
-        generate: (seed, files) => {
-          const manifestFiles = files.reduce(function(manifest, file) {
+        generate: (seed, files, entrypoints) => {
+          const manifestFiles = files.reduce((manifest, file) => {
             manifest[file.name] = file.path;
             return manifest;
           }, seed);
+          const entrypointFiles = entrypoints.main.filter(
+            fileName => !fileName.endsWith('.map')
+          );
 
           return {
             files: manifestFiles,
+            entrypoints: entrypointFiles,
           };
         },
       }),
diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json
index 8e0c9e5d0ca..87c5ea770e2 100644
--- a/packages/react-scripts/package.json
+++ b/packages/react-scripts/package.json
@@ -79,7 +79,7 @@
     "url-loader": "2.1.0",
     "webpack": "4.40.2",
     "webpack-dev-server": "3.2.1",
-    "webpack-manifest-plugin": "2.0.4",
+    "webpack-manifest-plugin": "2.1.1",
     "workbox-webpack-plugin": "4.3.1"
   },
   "devDependencies": {