Home

Awesome

vite-multiple-assets

vite-multiple-assets add support for multiple public asset directories to vite (or astro).

Document

Visit website

Feature

Quick setup would be in the vite.config.js:

export default defineConfig({
    // default is public folder
    publicDir:''
})

install

npm i -D vite-multiple-assets

Config options

{
    ".html": "text/html",
    ".js": "text/javascript",
    ".css": "text/css",
    ".png": "image/png",
    ".jpg": "image/jpeg",
    ".gif": "image/gif",
    ".svg": "image/svg+xml",
    ".json": "application/json",
    ".woff": "font/woff",
    ".woff2": "font/woff2",
    ".ttf": "font/ttf",
    ".eot": "font/eot",
    ".otf": "font/otf",
    ".wasm": "application/wasm",
    ".mjs": "text/javascript",
    ".txt": "text/plain",
    ".xml": "text/xml",
    ".wgsl": "text/wgsl",
    ".mp3": "audio/mpeg",
    ".mp4": "video/mp4",
    ".webm": "video/webm",
    ".webp": "image/webp",
    ".ico": "image/x-icon",
    ".tiff": "image/tiff",
    ".gz": "application/gzip",
    ".zip": "application/zip",
    ".rar": "application/x-rar-compressed",
    ".7z": "application/x-7z-compressed"
}

Note: In case the content type is not found, it will be automatically handled according to the mime-types library

In vite.config.ts

-Before `1.3.0`

import DynamicPublicDirectory from "vite-multiple-assets";

-After `1.3.0`
import {DynamicPublicDirectory} from "vite-multiple-assets";
// same level as project root
const dirAssets = ["libs/assets", "repo1/assets", ...];

// example
const mimeTypes = {
    '.acc': 'application/acc'
}

export default defineConfig({
    plugins: [
        DynamicPublicDirectory(dirAssets, {
            ssr: true,
            mimeTypes
        })
    ]
})
import {astroMultipleAssets} from "vite-multiple-assets";
const assets = ["libs/assets", "repo1/assets", ...];
export default defineConfig({
    integrations: [
        astroMultipleAssets(assets)
    ],
});
export default defineConfig({
   // default is public folder
   publicDir:["public","libs/assets","repo1/assets",...]
 })

Example