Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rvock opened this issue May 23, 2024 · 0 comments · Fixed by #1345
Closed

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

rvock opened this issue May 23, 2024 · 0 comments · Fixed by #1345

Comments

@rvock
Copy link

rvock commented May 23, 2024

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.

Kocal added a commit that referenced this issue Sep 20, 2024
…al plugin, to generate `entrypoints.json` file (Kocal)

This PR was merged into the main branch.

Discussion
----------

Replace `assets-webpack-plugin` dependency by an internal plugin, to generate `entrypoints.json` file

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes <!-- please update CHANGELOG.md file -->
| Deprecations? | no <!-- please update CHANGELOG.md file -->
| Issues        | Fix #969 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
| License       | MIT

This PR replaces the https://github.com/ztoben/assets-webpack-plugin dependency with an internal plugin, this allows us:
- to drop a dependency, and simplify the code (we don't need 10 ~options to generate the `entrypoints.json` for the WebpackEncoreBundle)
- to not depend on https://github.com/waysact/webpack-subresource-integrity, which is necessary to use the `integrity` options of https://github.com/ztoben/assets-webpack-plugin
- to generate the integrity data **after** files have been emitted

**Things done in this PR:**
- Re-implement https://github.com/ztoben/assets-webpack-plugin functionality as closely as possible
- Ensure tests pass without any modifications
- Ensure the branch works like before on a real project (in dev/prod/dev-server, with or without integrity hashes)

**Things not done in this PR:**
- #1269 will have to wait for another PR, I don't wanted to fix that here

Commits
-------

0529865 Replace `assets-webpack-plugin` dependency by an internal plugin, to generate `entrypoints.json` file
@Kocal Kocal closed this as completed in 15ad6a9 Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant