File tree 2 files changed +15
-12
lines changed
packages/gatsby-plugin-netlify/src
2 files changed +15
-12
lines changed Original file line number Diff line number Diff line change 1
1
import _ from "lodash"
2
2
import { writeFile , existsSync } from "fs-extra"
3
+ import { parse } from "path"
3
4
import kebabHash from "kebab-hash"
4
5
import { HEADER_COMMENT } from "./constants"
5
6
@@ -41,8 +42,18 @@ function createScriptHeaderGenerator(manifest, pathPrefix) {
41
42
return null
42
43
}
43
44
44
- // Always add starting slash, as link entries start with slash as relative to deploy root
45
- return linkTemplate ( `${ pathPrefix } /${ chunk } ` )
45
+ // convert to array if it's not already
46
+ const chunks = _ . isArray ( chunk ) ? chunk : [ chunk ]
47
+
48
+ return chunks
49
+ . filter ( script => {
50
+ const parsed = parse ( script )
51
+ // handle only .js, .css content is inlined already
52
+ // and doesn't need to be pushed
53
+ return parsed . ext === `.js`
54
+ } )
55
+ . map ( script => linkTemplate ( `${ pathPrefix } /${ script } ` ) )
56
+ . join ( `\n ` )
46
57
}
47
58
}
48
59
Original file line number Diff line number Diff line change 1
- import _ from "lodash"
2
1
import path from "path"
3
2
4
3
export function buildPrefixer ( prefix , ...paths ) {
5
4
return ( ...subpaths ) => path . join ( prefix , ...paths , ...subpaths )
6
5
}
7
6
8
- // Webpack stats map to an array if source maps are enabled.
9
- // We normalize to make direct map.
10
- function normalizeStats ( stats ) {
11
- return _ . mapValues ( stats . assetsByChunkName , script =>
12
- _ . isArray ( script ) ? script [ 0 ] : script
13
- )
14
- }
15
-
16
7
// This function assembles data across the manifests and store to match a similar
17
8
// shape of `static-entry.js`. With it, we can build headers that point to the correct
18
9
// hashed filenames and ensure we pull in the componentChunkName.
19
10
export default function makePluginData ( store , assetsManifest , pathPrefix ) {
20
11
const { program, pages : storePages } = store . getState ( )
21
12
const publicFolder = buildPrefixer ( program . directory , `public` )
22
13
const stats = require ( publicFolder ( `webpack.stats.json` ) )
23
- const chunkManifest = normalizeStats ( stats )
14
+ // Get all the files, not just the first
15
+ const chunkManifest = stats . assetsByChunkName
24
16
const pages = storePages
25
17
26
18
// We combine the manifest of JS and the manifest of assets to make a lookup table.
You can’t perform that action at this time.
0 commit comments