Skip to content

Commit

Permalink
#9828 add all the files from webpack.stats.json to _headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihai Blaga committed Mar 12, 2019
1 parent a3f64e0 commit 67b6819
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
7 changes: 7 additions & 0 deletions packages/gatsby-plugin-netlify/src/build-headers-program.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
Expand Down
12 changes: 2 additions & 10 deletions packages/gatsby-plugin-netlify/src/plugin-data.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
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.
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.
Expand Down

0 comments on commit 67b6819

Please sign in to comment.