From 67b68197755228455a6c65a4a51d95a240c56943 Mon Sep 17 00:00:00 2001 From: Mihai Blaga Date: Tue, 12 Mar 2019 21:08:29 +0200 Subject: [PATCH] #9828 add all the files from webpack.stats.json to _headers --- .../src/build-headers-program.js | 7 +++++++ packages/gatsby-plugin-netlify/src/plugin-data.js | 12 ++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/gatsby-plugin-netlify/src/build-headers-program.js b/packages/gatsby-plugin-netlify/src/build-headers-program.js index 068803f8361de..3d19d96bc9eb8 100644 --- a/packages/gatsby-plugin-netlify/src/build-headers-program.js +++ b/packages/gatsby-plugin-netlify/src/build-headers-program.js @@ -41,6 +41,13 @@ function createScriptHeaderGenerator(manifest, pathPrefix) { return null } + // If it's an array, return a string containing all the files + if (_.isArray(chunk)) { + return chunk + .map(script => linkTemplate(`${pathPrefix}/${script}`)) + .join(`\n `) + } + // Always add starting slash, as link entries start with slash as relative to deploy root return linkTemplate(`${pathPrefix}/${chunk}`) } diff --git a/packages/gatsby-plugin-netlify/src/plugin-data.js b/packages/gatsby-plugin-netlify/src/plugin-data.js index 079c86f89d971..4bbaae96ec8c4 100644 --- a/packages/gatsby-plugin-netlify/src/plugin-data.js +++ b/packages/gatsby-plugin-netlify/src/plugin-data.js @@ -1,18 +1,9 @@ -import _ from "lodash" import path from "path" export function buildPrefixer(prefix, ...paths) { return (...subpaths) => path.join(prefix, ...paths, ...subpaths) } -// Webpack stats map to an array if source maps are enabled. -// We normalize to make direct map. -function normalizeStats(stats) { - return _.mapValues(stats.assetsByChunkName, script => - _.isArray(script) ? script[0] : script - ) -} - // This function assembles data across the manifests and store to match a similar // shape of `static-entry.js`. With it, we can build headers that point to the correct // hashed filenames and ensure we pull in the componentChunkName. @@ -20,7 +11,8 @@ export default function makePluginData(store, assetsManifest, pathPrefix) { const { program, pages: storePages } = store.getState() const publicFolder = buildPrefixer(program.directory, `public`) const stats = require(publicFolder(`webpack.stats.json`)) - const chunkManifest = normalizeStats(stats) + // Get all the files, not just the first + const chunkManifest = stats.assetsByChunkName const pages = storePages // We combine the manifest of JS and the manifest of assets to make a lookup table.