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

augmentChunkHash with extract: true breaks hashing #315

Open
nstepien opened this issue Aug 25, 2020 · 5 comments
Open

augmentChunkHash with extract: true breaks hashing #315

nstepien opened this issue Aug 25, 2020 · 5 comments
Labels

Comments

@nstepien
Copy link
Contributor

My configuration looks like this:

  postcss({
    extract: true,
    minimize: process.env.NODE_ENV === 'production'
  })

https://rollupjs.org/guide/en/#augmentchunkhash
https://github.com/egoist/rollup-plugin-postcss/blob/master/src/index.js#L140
The augmentChunkHash hook is used to augment the hash of chunks (entry js file + its dependencies), not assets, so I don't understand why this is used. It's not even filtering which chunk gets its hash augmented.
This is causing all my js files to have new a hash on every build, even when nothing has changed.

The extracted stylesheet's hash should also not be based on the entry file's hash, it should have its own independent hash.

Removing the augmentChunkHash hook completely fixes first problem. rollup-plugin-postcss will still need to hash the stylesheet based on its content.

@nstepien
Copy link
Contributor Author

Using the name property with emitFile is enough to automatically hash that file.

https://rollupjs.org/guide/en/#thisemitfileemittedfile-emittedchunk--emittedasset--string

Otherwise if a name is supplied, this will be used as substitution for [name] in the corresponding output.chunkFileNames or output.assetFileNames pattern, possibly adding a unique number to the end of the file name to avoid conflicts.

@rproserpio
Copy link

Yeah, i'm observing the same behavior in my project. This issue breaks caching.

@rproserpio
Copy link

PR #226 already uses the emitFile API with the name property, although i believe should be better to pass the actual code without sourceMappingUrl as the source property to let rollup handle the hash generation, and then append the appropriatesourceMappingUrl directly to the asset source in the bundle, when we have the sourcemap filename.
If the hash is computed based on the effective output file content, is there any other reason to use augmentChunkHash?

@AlexGalays
Copy link

Did anyone find a fork that fixes these kind of big/completely breaking bugs?

@rproserpio
Copy link

You can go relatively far using something like patch-package to amend specific things until the maintainers have the time to look at the submitted PRs.
To emit an asset together with its sourcemap you can do somenthing like the following (stolen from now deleted code in rollup-plugin-svelte):

function emitFileWithSourcemap(bundle, name, code, map) {
	const ref = this.emitFile({
		type: 'asset',
		name: name,
		source: code
	});
	const filename = this.getFileName(ref);
	const mapFilename = `${filename}.map`;
        // TODO handle inline, hidden or disabled sourcemap options
	bundle[filename].source += `\n/*# sourceMappingURL=${path.basename(mapFilename)} */`;
	this.emitFile({
		fileName: mapFilename,
		type: 'asset',
		source: map
	});
}

This function lets Rollup handle the naming and the hashing, using its output.assetFileNames conf. You can then completely remove augmentChunkHash, since the hashing is consistent with the extracted file content.
If you use js dynamic imports that import css you may want to also look at #317 to avoid non deterministic source concatenation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants