Skip to content

Commit 6c8288a

Browse files
committed
fix too long chunk names
1 parent 69c4795 commit 6c8288a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packages/gatsby/src/utils/js-chunk-names.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,21 @@ export function generateComponentChunkName(componentPath: string): string {
4646
} else {
4747
const { program } = store.getState()
4848
const directory = program?.directory || `/`
49-
const name = pathRelative(directory, componentPath)
49+
let name = pathRelative(directory, componentPath)
5050

51-
const chunkName = `component---${replaceUnifiedRoutesKeys(
51+
const prefix = `component---`
52+
const maxLength = 255 - directory.length - prefix.length
53+
54+
// Shorten path name to not exceed max length of 255 characters
55+
if (name.length > maxLength) {
56+
const hash = require(`crypto`)
57+
.createHash(`sha1`)
58+
.update(name)
59+
.digest(`base64`)
60+
name = `${name.substring(0, maxLength - 41)}-${hash}`
61+
}
62+
63+
const chunkName = `${prefix}${replaceUnifiedRoutesKeys(
5264
kebabCase(name),
5365
name
5466
)}`

0 commit comments

Comments
 (0)