symfony / webpack-encore

A simple but powerful API for processing & compiling assets built around Webpack
https://symfony.com/doc/current/frontend.html
MIT License
2.23k stars 198 forks source link

Integrity hashes do not work if contenthash is a query string #1269

Closed rvock closed 1 month ago

rvock commented 6 months ago

If you are using the [contenthash] as a query string, the integrity hashes are not generated.

Example webpack.config.js

const Encore = require('@symfony/webpack-encore');

Encore
    // directory where compiled assets will be stored
    .setOutputPath('build/')
    // public path used by the web server to access the output path
    .setPublicPath('/build/')
    .setManifestKeyPrefix('build/')

    // hash as querystring instead of in filename
    .configureFilenames({
        js: '[name].js?[contenthash]',
    })

    .addEntry('example', './src/example.js')

    .disableSingleRuntimeChunk()

    .enableVersioning(Encore.isProduction())

    .enableIntegrityHashes(Encore.isProduction())
;

module.exports = Encore.getWebpackConfig();

Generated entrypoints.json

{
  "entrypoints": {
    "example": {
      "js": [
        "/static/build/example.js?621df54d056c27d5eaa8"
      ]
    }
  },
  "integrity": {}
}

The problem exists, because entry-files-manifest.js assumes the filename is a a valid file: https://github.com/symfony/webpack-encore/blob/6b75c4dd963c613ddc19fa2748e0b6bcc4512c16/lib/plugins/entry-files-manifest.js#L52-L57

If the query string would be stripped, the file path should be correct.