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

fix(vite): avoid applying css transform on bundle generation #1872

merged 1 commit into from Nov 13, 2022

fix(vite): avoid applying css transform on bundle generation #1872

merged 1 commit into from Nov 13, 2022


Copy link

@equt equt commented Nov 12, 2022

close #1850

@equt equt requested a review from antfu as a code owner November 12, 2022 03:53
Copy link

netlify bot commented Nov 12, 2022

Deploy Preview for unocss ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit f4ba7f4
🔍 Latest deploy log
😎 Deploy Preview
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Contributor Author

equt commented Nov 12, 2022

Currently, the global mode for the Vite integration will not replace the generated __VITE_PUBLIC_ASSET__hash__ asset URL as I've mentioned in #1850.

And as it turns out, inside the post transformer

return await applyCssTransform(layer === LAYER_MARK_ALL
? result.getLayers(undefined, Array.from(vfsLayers))
: result.getLayer(layer) || '', `${chunk.fileName}.css`, options.dir)

Only the pre-plugin vite:css from Vite gets called

async function applyCssTransform(css: string, id: string, dir: string | undefined) {
const {
postcss = true,
} = await getConfig()
if (!cssPlugins.get(dir) || !postcss)
return css
// @ts-expect-error no this context
const result = await cssPlugins.get(dir).transform(css, id)
if (!result)
return css
if (typeof result === 'string')
css = result
else if (result.code)
css = result.code
css = css.replace(/[\n\r]/g, '')
return css

Since the post-one is missing, we could never turn the __VITE_PUBLIC_ASSET__hash__ back to what it should really be.

This only happens for the global mode, and only for the build rather than the dev.

This PR simply removes the applyCssTransform, as I don't see any necessary reason why it should be performed upon a generated chunk.

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

Successfully merging this pull request may close these issues.

__VITE_PUBLIC_ASSET__hash__ doesn't get replaced in the generated output
3 participants