-
-
Notifications
You must be signed in to change notification settings - Fork 52
cloudflare adapter breaks rollupOptions output filenames #334
Comments
@mschoeffmann Thank you for the report. Is this If so I'm afraid that it won't be supported, since all SSR related files must be under the path |
@alexanderniebuhr the expected path would be |
Okay understood. I don't think it would be working with chunks. Only static assets like css, etc. Also I don't think this is Cloudflare specific, but rather a generic issue, when the option I also think their is a different configuration for that, let me see if I can find it. |
I think the adapter already knows which files belong to the client and which belong to the client. Because without using the output options, all the files are in the right place.
But right now, also assets are not working. The css file for example lands in _worker.js subdirectory. |
I'll try to see if the same behavior happens with the Node adapter, to see if this is a core issue. |
Update: I also tried this with a ready-to-migrate web project and noticed especially .css files and .jpg files were inside the wrong folder. |
Hahaha - coincidence - just done... #334 (comment) |
It's pretty unlikely that this is going to work. Netlify and Vercel need files to be in special folders for their deployment. It's not really configurable. |
The node adapter has the same issue when using |
@mschoeffmann Any reason why you can't use https://docs.astro.build/en/reference/configuration-reference/#buildassets to change the name of |
Overriding |
@matthewp Yes, true. My goal is to:
Links about the filenames:
Thanks for the quick response @matthewp and @alexanderniebuhr. |
It's not really a workaround, those are the methods of adjusting output filenames for client-side code. |
Yeah I guess for "2." |
@matthewp yep - sorry :-) I wrote a quick integration to test this: export const genericClientFilenames = () => {
let integration = {
name: 'generic-client-filenames',
hooks: {
'astro:build:setup': ({ vite, target }) => {
if (target === 'client') {
console.log(vite.build.rollupOptions.output)
vite.build.rollupOptions.output.entryFileNames =
'_static-CLIENT/entry.[hash].js'
vite.build.rollupOptions.output.chunkFileNames =
'_static-CLIENT/chunk.[hash].js'
vite.build.rollupOptions.output.assetFileNames =
'_static-CLIENT/asset.[hash][extname]'
console.log(vite.build.rollupOptions.output)
}
if (target === 'server') {
console.log(vite.build.rollupOptions.output)
//// COMMENTED OUT BECAUSE ENTRY AND CHUNK FOR SERVER BUILD ARE GENERATED ON THE FLY BY FUNCTIONS --->
// vite.build.rollupOptions.output.entryFileNames =
// '_static/entry.[hash].js'
// vite.build.rollupOptions.output.chunkFileNames =
// '_static/chunk.[hash].js'
//// COMMENTED OUT BECAUSE ENTRY AND CHUNK FOR SERVER BUILD ARE GENERATED ON THE FLY BY FUNCTIONS ---<
vite.build.rollupOptions.output.assetFileNames =
'_static-SERVER/asset.[hash][extname]'
console.log(vite.build.rollupOptions.output)
}
},
},
}
return integration
}
export default genericClientFilenames The result is:
So for me it looks like the asset files were generated only for server target? the -client and -server folder suffix as well as the console statements are for better debugging. |
I found a working solution now by overwriting the each *FileNames key of the output object with a function to replace I'm not sure if this is the best way, and it still looks strange that somehow css assets are generated in "server" target. Maybe I'll release an integration package on npm for this one ... Reading the mentioned threads sounds like more people want to get rid of the confusing filenames. // ./src/integrations/generic-client-filenames.ts
import type { AstroIntegration } from 'astro'
import type { PreRenderedChunk, PreRenderedAsset, OutputOptions } from 'rollup'
export const genericClientFilenames = () => {
let integration: AstroIntegration = {
name: 'generic-client-filenames',
hooks: {
'astro:build:setup': ({ vite }) => {
const usedOutputOptions = vite.build.rollupOptions.output as OutputOptions
const originalOutputOptions = Object.assign(
{},
vite.build.rollupOptions.output,
) as OutputOptions
usedOutputOptions.entryFileNames = (chunkInfo: PreRenderedChunk) => {
const originalNames =
typeof originalOutputOptions.entryFileNames === 'function'
? originalOutputOptions.entryFileNames(chunkInfo)
: originalOutputOptions.entryFileNames
return originalNames.replace('[name]', 'entry')
}
usedOutputOptions.chunkFileNames = (chunkInfo: PreRenderedChunk) => {
const originalNames =
typeof originalOutputOptions.chunkFileNames === 'function'
? originalOutputOptions.chunkFileNames(chunkInfo)
: originalOutputOptions.chunkFileNames
return originalNames.replace('[name]', 'chunk')
}
usedOutputOptions.assetFileNames = (assetInfo: PreRenderedAsset) => {
const originalNames =
typeof originalOutputOptions.assetFileNames === 'function'
? originalOutputOptions.assetFileNames(assetInfo)
: originalOutputOptions.assetFileNames
return originalNames.replace('[name]', 'asset')
}
},
},
}
return integration
}
export default genericClientFilenames // ./astro.config.mjs
import genericClientFilenames from './src/integrations/generic-client-filenames'
...
export default defineConfig({
...
integrations: [genericClientFilenames()],
build: {
assets: '_static',
},
...
}) |
Great to hear you found a way to solve your use-case, I'll close the issue for now. |
For reference: |
That's great. I suggest posting this to the |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
Using rollupOptions like entryFileNames, chunkFileNames and assetFileNames for reasons (withastro/astro#7469, withastro/astro#8549, withastro/astro#5787, ...) moves the files from
./dist
folder to./dist/_render.js
which results in 404 after deploying.check out the min. reproduction stackblitz and run the command
npm run build
first with the above config, and second with the above lines commented out. there it only affects the .css file but on larger projects it affects all bundled chunks and assets.not working: css is _worker.js subfolder:

working without output filename config: css is in _astro subfolder:

What's the expected result?
bundled files in
./_static
as configured. works without adapter and'static'
output mode.Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-tzkvup?file=src%2Flayouts%2FLayout.astro%2Castro.config.mjs&on=stackblitz
Participation
Changes: edited screenshot annotations and fixed issue links
The text was updated successfully, but these errors were encountered: