Closed LefanTan closed 1 year ago
This is expected behavior, when CSS is bundled into a file it is named after the first page it is used on and the tailwind integration injects styles onto every page by default so 404
is the first page alphabetically.
If you want more control over the naming of the output files you can configure rollup inside the Astro config:
import { defineConfig } from 'astro/config'
export default defineConfig({
vite: {
build: {
rollupOptions: {
output: {
entryFileNames: 'entry.[hash].mjs',
chunkFileNames: 'chunks/chunk.[hash].mjs',
assetFileNames: 'assets/asset.[hash][extname]',
},
},
},
},
})
If you need more control over the importing of your tailwind styles you can disable the default style sheet and import your own:
import { defineConfig } from 'astro/config';
export default defineConfig({
integrations: [
tailwind({
applyBaseStyles: false,
}),
],
});
/* /src/styles/base.css */
@tailwind base;
@tailwind components;
@tailwind utilities;
// /src/pages/index.astro
---
import '../styles/base.css'
---
Closing as a duplicate of https://github.com/withastro/astro/issues/7469
I just created an integration for this: https://www.npmjs.com/package/astro-generic-build-filenames
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
When tailwind is installed and a
404.astro
page is present, the build version of the project will always include the CSS files from the 404 page in all the pages. Depending on the file size of404
's CSS, this can have a downstream effect on load performanceWhen visiting
/
, I don't think stylesheets related to404.css
should be imported.I've noticed that this could also happened to nested 404 pages, though i'm unable to replicate it in the sandbox
What's the expected result?
Stylesheet related to 404 shouldn't be imported when visiting normal pages.
Link to Minimal Reproducible Example
https://codesandbox.io/p/sandbox/withered-snowflake-zmv8rm?file=/src/pages/nested/404.astro:9,1
Participation