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

Exclude original images from output dir #8143

Closed
1 task
pkolt opened this issue Aug 18, 2023 · 6 comments · Fixed by #8954
Closed
1 task

Exclude original images from output dir #8143

pkolt opened this issue Aug 18, 2023 · 6 comments · Fixed by #8954
Labels
- P2: nice to have Not breaking anything but nice to have (priority) feat: assets Related to the Assets feature (scope)

Comments

@pkolt
Copy link

pkolt commented Aug 18, 2023

What version of astro are you using?

2.10.9

Are you using an SSR adapter? If so, which one?

None

What package manager are you using?

npm

What operating system are you using?

Mac

What browser are you using?

Chrome

Describe the Bug

Hi guys!

I'm using Astro with the assets module.

After executing the command - astro build, my cache folder contains image thumbnails.

But the original images are also in the cache folder.

Is it possible to add some setting to adjust Astro to remove original images?

The original images weigh a lot and slow down the deployment process to github pages.

What's the expected result?

There are no original images in the cache folder.

Link to Minimal Reproducible Example

https://github.com/pkolt/pkolt.ru

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Aug 18, 2023
@lilnasy lilnasy added - P2: nice to have Not breaking anything but nice to have (priority) pkg: image Related to the `@astrojs/image` package (scope) and removed needs triage Issue needs to be triaged labels Aug 18, 2023
@Princesseuh Princesseuh added feat: assets Related to the Assets feature (scope) and removed pkg: image Related to the `@astrojs/image` package (scope) labels Aug 18, 2023
@Princesseuh
Copy link
Member

What do you mean by "your cache folder"? Do you mean the build output or the cache folder in node_modules?

@pkolt
Copy link
Author

pkolt commented Aug 19, 2023

Hi @Princesseuh !

Yes, the cache folder in node_modules.
My cache folder is ./cache, this is specified in my config:

// astro.config.mjs
import { defineConfig, sharpImageService } from 'astro/config';
import react from '@astrojs/react';
import sitemap from '@astrojs/sitemap';
import mdx from '@astrojs/mdx';

/** @type {import('astro/config').AstroUserConfig} */
const config = {
  site: 'https://pkolt.ru',
  integrations: [react(), sitemap(), mdx()],
  compressHTML: true,
  markdown: {
    gfm: true,
    syntaxHighlight: 'prism',
  },
  outDir: 'out',
  cacheDir: 'cache', // <---- CACHE FOLDER
  experimental: {
    assets: true,
  },
  image: {
    service: sharpImageService(),
  },
};

export default defineConfig(config);

@Princesseuh
Copy link
Member

Princesseuh commented Aug 19, 2023

Hmm, we don't cache the original images, only the transformed versions, the goal is to avoid redoing the transforming step. Are you sure you're seeing the original files?

@pkolt
Copy link
Author

pkolt commented Aug 19, 2023

Hi @Princesseuh !

Yes, you can see for yourself.

git clone [email protected]:pkolt/pkolt.ru.git
cd pkolt.ru
npm ci
npm run build

For example, I have a large image file (3.4Mb) - src/assets/blog/overview-wemos-d1-mini/wemos_d1_mini_1.jpg

After executing the build command npm run build, this file is in the output directory - out/_astro/wemos_d1_mini_1.ccc1c605.jpg.

We can even compare both of these files by hash, they are the same file:

% md5sum src/assets/blog/overview-wemos-d1-mini/wemos_d1_mini_1.jpg
5847f402f9eb558bb386596e56d7dd97  src/assets/blog/overview-wemos-d1-mini/wemos_d1_mini_1.jpg

% md5sum out/_astro/wemos_d1_mini_1.ccc1c605.jpg
5847f402f9eb558bb386596e56d7dd97  out/_astro/wemos_d1_mini_1.ccc1c605.jpg

This is very bad, because the original images are very large, I would not want them to end up in the output directory.

@Princesseuh
Copy link
Member

Princesseuh commented Aug 19, 2023

Ah, so not in the cache folder, in the output build. Yes this is a known "issue", though it's more of a design choice because people often like having features like "Click to see original", or maybe show the original as a fallback in the case of a picture element and it's not possible for us to statically know if you're using those original assets outside the optimization pipeline or not

We could probably have an optional option to delete the original files if an optimized version exists, should be doable, though we'd have to carefully document the side effects it can cause

@evgrekov
Copy link

evgrekov commented Sep 1, 2023

Hello! I would like to express my strong desire for the inclusion of an optional feature that allows us to delete the original files from output folder. In my situation, I have 20,000 thumbnails alongside their original versions, and this is leading to significant storage consumption and longer deployment times. Thank you!

Ty3uK added a commit to Ty3uK/astro that referenced this issue Sep 1, 2023
Related to withastro#8143

Setting `assetsRemoveOriginals: true` will remove original images from `dist/_astro` folder
Ty3uK added a commit to Ty3uK/astro that referenced this issue Sep 1, 2023
Related to withastro#8143

Setting `assetsRemoveOriginals: true` will remove original images from `dist/_astro` folder
Ty3uK added a commit to Ty3uK/astro that referenced this issue Sep 2, 2023
Related to withastro#8143

Setting `assetsRemoveOriginals: true` will remove original images from `dist/_astro` folder
@Princesseuh Princesseuh changed the title Exclude origin image from Astro cache dir Exclude original images from output dir Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority) feat: assets Related to the Assets feature (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants