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

Do i need to add the g folder to .gitignore ? #16

Closed
carlos-dubon opened this issue Mar 3, 2022 · 6 comments
Closed

Do i need to add the g folder to .gitignore ? #16

carlos-dubon opened this issue Mar 3, 2022 · 6 comments

Comments

@carlos-dubon
Copy link

Do i need to add the static/g folder to .gitignore ?

It's constantly generating new files...

@xiphux
Copy link
Owner

xiphux commented Mar 3, 2022

I think it's up to you, there are pros and cons.

Typically, yes, you'd only commit the original files and gitignore the generated files, since they can be regenerated off of the original files, so you could save the space in your repo.

You would have to regenerate them after a fresh checkout of the repo, though, so there might be certain circumstances where it makes sense to also commit the generated files. One example would be if you have a lot of images and your project is deployed using CI/CD runners taking a fresh checkout, so you'd spend a lot of processing time repeatedly regenerating all the images for every CI/CD run. You could commit the generated files and save the processing time at the expense of using more repo space.

@xiphux xiphux closed this as completed May 2, 2022
@robertbarnes93
Copy link

@xiphux, I thought it would be a distraction for me to create a new issue, but I was also looking to keep my repo clean by adding static/g to .gitignore. However, I noticed that these generated images (which are not committed to the repo) are not displayed on production.

For context, I use @sveltejs/adapter-cloudflare and Cloudflare Pages. When I run npm run build and npm run dev, I see that the files are being generated in .svelte-kit/cloudflare. Interestingly enough, in Preview it looks like the images still reference static/g from root instead of .svelte-kit/cloudflare/g. Is this intended behavior, or could this be an issue related to the Cloudflare adapter or something else?

Thank you for making this module! :)

@xiphux
Copy link
Owner

xiphux commented Aug 1, 2022

I'm not really familiar with adapter-cloudflare and how it deploys. Are the assets from .svelte-kit/cloudflare including the generated images in g/ served from the root of the Cloudflare Pages domain? You might need to define a publicPath for your images. By default if you have an inputDir of static and an outputDir of static/g it should rewrite the image urls to have the g/ in front of them because it detects that outputDir lives within inputDir - but if that's not your setup, you could override that path prefix with publicPath.

@robertbarnes93
Copy link

It looks like the browser is trying to retrieve g/image.avif (as intended) but it returns a 404. I assume the image is not being generated and publicPath won't be able to address that problem?

If it matters, on my local environment I can find the optimized images in .svelte-kit/cloudflare/g.

@xiphux
Copy link
Owner

xiphux commented Aug 1, 2022

If you can find the images in your local environment after running build, then I'd guess it's either:

  • The generated images aren't getting published to / made available on cloudflare due to some sort of missing required configuration, or
  • They are getting published, but aren't being served at the url we're expecting
    Unfortunately, that's about the extent of what I can guess - I don't really know anything about the cloudflare adapter and how cloudflare pages hosting/configuration works. Maybe is there a way for you to browse the files on your cloudflare deployment and see if the generated images are there?

@robertbarnes93
Copy link

I was able to get functionality to work by making two changes in my project:
• In svelte.config.js, change@sveltejs/adapter-cloudflare with @sveltejs/adapter-static.
• In build output directory settings on Cloudflare Pages, change .svelte-kit/cloudflare with build.

I'm not sure what the root cause is, but I guess there is a compatibility issue with the Cloudflare adapter.

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

No branches or pull requests

3 participants