sapphi-red / vite-plugin-static-copy

rollup-plugin-copy with dev server support.
MIT License
270 stars 29 forks source link

Documentation: Some words on what "good uses" for this package are would be welcome #86

Closed hybridherbst closed 4 months ago

hybridherbst commented 6 months ago

The readme currently notes:

Before you use this plugin, consider using public directory or import in JavaScript. In most cases, these will work.

However, I keep coming back to this plugin because of the glob and dynamic import limitations in vite, so I thought I'd ask here if that is actually an expected usecase, and potentially some notes on that can go into the readme.

Consider an example structure for a photo albums project, and some photos have a story markdown file.
The photo album is on a specific location on disk, unrelated to the vite project (using sveltekit here, but shouldn't matter for the question). There are some topics and subtopics where photos are categorized in.
It is not viable nor desired to just copy the entire set of photo albums into the public directory.

- someDirectoryOnDisk
  - topic1
    - photo1.png
    - story1.md
    - photo2.png
    - subtopic
      - photo3.png
      - story3.md
  - topic2
    - photo3.png
    - story4.md

Somewhere else on disk, we have a svelte project:

- someDevDirectory
  - package.json
  - vite.config.ts
  - src/routes
    - +page.server.ts
    - +page.svelte

Would you say that is a typical usecase for vite-plugin-static-copy?

The flow would be:

It feels "glued together" compared to letting vite handle all imports and file copying, but I can't figure out if/how that would work given the limitations of import.meta.glob and dynamic import with a single variable. Letting vite handle it would also allow using image optimizations etc., that seem harder to add this way.

sapphi-red commented 6 months ago

I'd recommend using symlinks in that case. For example, linking someDirectoryOnDisk to someDevDirectory/src/albums will let you use import.meta.glob.

hybridherbst commented 6 months ago

I see. So I would

Does that sound right?

sapphi-red commented 6 months ago

I guess that would work.

sapphi-red commented 4 months ago

I'll close this for now as I don't know how to clarify it.