Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

111
Visualizações
Use Compilation Hash for asset/resource files in Webpack 5

I'm trying to use the compilation hash for asset/resource file names but no matter what I try it just generates a different hash for every file in the asset/resource output. The chunk file names all get the same and correct compilation hash.

For example, the main bundle files are all correct:

appbundle.42cf6539b0e35868deab.js

polyfillsbundle.42cf6539b0e35868deab.js

etc..

However, the images in the assets folder look like this, with different hashes. Is there a way to get them to match the compilation hash like the bundle chunks?

image1.ec620b3ff0d269c77f1b.svg

image2.984ca5bc273b4992cb6c.svg

etc..

Relevant webpack config:

output:
        {
            filename: '[name].[hash][ext]',
            chunkFilename: '[name].[hash][ext]',
            publicPath: './dist/',
            path: path.resolve(__dirname, 'dist'),
            assetModuleFilename: 'assets/[name].[hash][ext]'
        }
      ...

module: {
    rules: 
    [
        ...
        {
            test: /\.(eot|woff|woff2|ttf|png|jpg|gif|svg|ico)$/,
            type: 'asset/resource'
        },  
        ...             
    ]
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

But what are you trying to achieve?

You are getting a new hash per image file, because with asset/resource you asked Webpack to emit resources to separate files.
When you use [hash] placeholder, Webpack would generate a hash out of the filename. Since you have different filenames ~> different hashes.

If you want to add some random suffix per build to your resources, I'd do something like:

const seed = new Date().getTime() // or your generation strategy

module.exports = {
. . .
output:
        {
            . . .
            assetModuleFilename: `assets/[name].${seed}[ext]`
        }
      ...
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda