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 199 forks source link

`enableIntegrityHashes` and `configureFilenames` can conflict together #1340

Closed Kocal closed 2 months ago

Kocal commented 2 months ago

While working on #969, I've found that the Encore.enableIntegrityHashes() feature was doing nothing, because my Encore.configureFilenames() configuration:

Encore.configureFilenames({
    js: '[name].js?v=[contenthash:8]',
    css: '[name].css?v=[contenthash:8]',
    assets: 'assets/[name].[ext]?v=[contenthash:8]',
})

Using a query-parameter to store contenthash instead of the filename itself, is a strategy mentioned in https://github.com/symfony/webpack-encore/issues/1266.

If I had console.log({outputPath: webpackConfig.outputPath, file, publicPath, filePath }) below lines https://github.com/symfony/webpack-encore/blob/main/lib/plugins/entry-files-manifest.js#L55-L58, it outputs:

{
  outputPath: '/Users/kocal/path-to-app/public/build',
  file: '/build/app.js?v=3af532f5',
  publicPath: '/build/',
  filePath: '/Users/kocal/path-to-app/public/build/app.js?v=3af532f5'
}

The next line fs.existsSync(filePath) can only returns false, because it will try to find a file explicitly named app.js?v=3af532f5, which... does not exist. But app.js file does exist!

If I remove my custom filenames formats, as expected I can see the integrity hashes in entrypoints.json file.


What should we do?

Should we check if ? is present in the filename, and if yes, remove ? and everything after? Should we keep the actual behavior but log a warning instead?

stof commented 2 months ago

Duplicate of https://github.com/symfony/webpack-encore/issues/1269