Skip to content

Commit

Permalink
fix too long chunk names
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger committed Jun 24, 2022
1 parent a3d3b12 commit fb98492
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/gatsby/src/utils/js-chunk-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,21 @@ export function generateComponentChunkName(componentPath: string): string {
} else {
const { program } = store.getState()
const directory = program?.directory || `/`
const name = pathRelative(directory, componentPath)
let name = pathRelative(directory, componentPath)

const chunkName = `component---${replaceUnifiedRoutesKeys(
const prefix = `component---`
const maxLength = 255 - directory.length - prefix.length

// Shorten path name to not exceed max length of 255 characters
if (name.length > maxLength) {
const hash = require(`crypto`)
.createHash(`sha1`)
.update(name)
.digest(`base64`)
name = `${name.substring(0, maxLength - 41)}-${hash}`
}

const chunkName = `${prefix}${replaceUnifiedRoutesKeys(
kebabCase(name),
name
)}`
Expand Down

0 comments on commit fb98492

Please sign in to comment.