Skip to content
Advertisement

What does the :8 mean in Webpack’s output variables. filename: [name][contenthash:8]?

I’m configuring Webpacks output and i have run into some examples which have this unusual syntax added on the end.

output: {
    filename: '[name][fullHash:8].bundle.js',
    chunkFilename: '[name][fullHash:8].bundle.js',
    path: `${__dirname}/dist`,
    publicPath: "/",
},

Ok now you see the :8’s after fullhash? what extra feature does it provide? My first guess was UTF-8??? But that’s just a stab in the dark.

Advertisement

Answer

So from a quick little search in the docs, I found this one section which talks about it

The length of hashes ([hash], [contenthash] or [chunkhash]) can be specified using [hash:16] (defaults to 20). Alternatively, specify output.hashDigestLength to configure the length globally.

So going by that, it would probably mean that [fullHash:8] would produce a hash of length 8, which I suppose I would advice against, and would be better off to keep it at the default of 20 (by just removing the :8).

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement