Skip to content

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

Closed
@rvock

Description

@rvock

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:

const filePath = path.resolve(
webpackConfig.outputPath,
file.replace(publicPath, '')
);
if (fs.existsSync(filePath)) {

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions