-
-
Notifications
You must be signed in to change notification settings - Fork 425
Augmented chunk hashes based on imported css code #1665
Augmented chunk hashes based on imported css code #1665
Conversation
14802b0
to
cbfb515
Compare
const css_hashing = () => { | ||
const css_hashes: Record<string, string> = {}; | ||
return <Plugin>{ | ||
name: 'sapper-css-hashing', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this plugin be combined with the sapper-css-injection
plugin? It seems like the hashing is really necessary because of what that plugin is doing and isn't something we'd use in a standalone fashion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs to be before the css chunk plugin and is also critical for the client chunk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Actually this exact issue should also apply to rollup-plugin-css-chunks
as there is also some chunk.code
stuff happening without a corresponding augmentChunkHash
hook. So sapper-css-hashing
should actually fix this for the css chunk plugin as well as the sapper rollup compiler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping to combine the sapper-css-injection
plugin with rollup-plugin-css-chunk
: domingues/rollup-plugin-css-chunks#8. There's no reason that our css injection functionality couldn't be used by other Rollup projects, so I think it'd better live as a project separate from Sapper
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about it this maybe could have been solved on rollup-plugin-css-chunks
level. I already tried to update to the newest version, but that had a major update in the mean time. Using the newest version in sapper had noticeable side effects. Fix it there might still need extra work on sapper side, I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just sent #1666 to update to the latest rollup-plugin-css-chunks
. I had to bump Rollup as well to make it work
cbfb515
to
21ab0bd
Compare
18ea684
to
a6f05a0
Compare
It looks like this will need to be rebased. I sent a small PR in #1677 and didn't realize it would conflict with this |
a6f05a0
to
f53488c
Compare
f53488c
to
82ae869
Compare
This comment has been minimized.
This comment has been minimized.
82ae869
to
dba0997
Compare
@benmccann Ok, I rebased and updated the approach. Maybe you could have another look. I had to add |
It looks like there's a merge conflict here. This one was pretty complicated to understand and test. I wonder if it might be better to just make sure this works as intended in SvelteKit instead? SvelteKit uses Vite for CSS bundling which is a completely different set of code, so there's a good chance this issue doesn't exist there |
Everything is working as expected in SvelteKit, I'd say. Running |
SvelteKit 1.0 is now out and Sapper is deprecated, so I'm going to close this |
Before submitting the PR, please make sure you do the following
Tests
npm test
and lint the project withnpm run lint
Fixes: #1660
Currently the chunk hashes don't include "injected" css code coming from script css imports. This is because the injection is happening in bundle hooks and at this stage all depending chunk imports will already be resolved using hashes that don't "react" to css changes. This is especially crucial in caching environments.
To ensure that the chunk hashes also change as soon as imported css gets updated this PR adds a
css_hashing
plugin to the rollup compiler. TheaugmentChunkHash
hook is utilised to provide a hash based on all imported css codes.