nguyenbatranvan / vite-multiple-assets

npm package
https://www.npmjs.com/package/vite-multiple-assets
8 stars 7 forks source link

Output asset folders at a subdirectory #9

Open Keavon opened 7 months ago

Keavon commented 7 months ago

I have a monorepo with this structure:

In vite.config.ts I have this:

plugins: [DynamicPublicDirectory(["../external-assets"])]

Per default, anything in the public directory (like favicon.ico) gets served at the root like localhost:8080/favicon.ico. This also means, thanks to your extension allowing me to have essentially multiple public directories, I'm currently able to also access localhost:8080/asset-1.json and localhost:8080/asset-2.json. However, I would prefer everything from the external-assets directory by served under the /external-assets subdirectory, like: localhost:8080/external-assets/asset-1.json.

One way that I'm not fond of is changing my monorepo directory structure like so:


Proposal: change the plugin's first argument (dirAssets in DynamicPublicDirectory(dirAssets, mimeTypes)) from string[] to (string | { in: string, out: string })[] so the additional asset directories can each be specified as just an input (where the files are dumped alongside the public folder contents) or as an object listing both an input and output, where the latter specifies the folder(s) that contain its contents. So my use case explained above would become:

plugins: [
    DynamicPublicDirectory([
        { in: "../external-assets", out: "external-assets" }
    ])
]
nguyenbatranvan commented 7 months ago

I have a monorepo with this structure:

  • external-assets/

    • asset-1.json
    • asset-2.json
  • frontend/

    • src/

    • public/

    • favicon.ico

    • vite.config.ts

In vite.config.ts I have this:

plugins: [DynamicPublicDirectory(["../external-assets"])]

Per default, anything in the public directory (like favicon.ico) gets served at the root like localhost:8080/favicon.ico. This also means, thanks to your extension allowing me to have essentially multiple public directories, I'm currently able to also access localhost:8080/asset-1.json and localhost:8080/asset-2.json. However, I would prefer everything from the external-assets directory by served under the /external-assets subdirectory, like: localhost:8080/external-assets/asset-1.json.

One way that I'm not fond of is changing my monorepo directory structure like so:

  • external-assets/

    • external-assets/

    • asset-1.json

    • asset-2.json

  • frontend/

    • ...

Proposal: change the plugin's first argument (dirAssets in DynamicPublicDirectory(dirAssets, mimeTypes)) from string[] to (string | { in: string, out: string })[] so the additional asset directories can each be specified as just an input (where the files are dumped alongside the public folder contents) or as an object listing both an input and output, where the latter specifies the folder(s) that contain its contents. So my use case explained above would become:

plugins: [
    DynamicPublicDirectory([
        { in: "../external-assets", out: "external-assets" }
    ])
]

Thanks for your problem!!

maxpatiiuk commented 1 month ago

I would really love to see this feature @nguyenbatranvan do you have plans for adding it?

Would you be open to clarifying the licensing policy for this project to instruct users and contributors?

nguyenbatranvan commented 1 month ago

I would really love to see this feature @nguyenbatranvan do you have plans for adding it?

Would you be open to clarifying the licensing policy for this project to instruct users and contributors?

I will be back as soon as possible to resolve these issues