You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP

vite-plugin-serve-static

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-serve-static

A Vite plugin for serving static files during local development

1.2.0
latest
Version published
Weekly downloads
4K
106.63%
Maintainers
1
Weekly downloads
 
Created

vite-plugin-serve-static

npm vite license: MIT

A simple Vite plugin for serving arbitrary static files that aren't in your public directory.

// vite.config.ts
import path from "path";
import { defineConfig } from "vite";
import serveStatic from "vite-plugin-serve-static";

const serveStaticPlugin = serveStatic([
  {
    pattern: /^\/metadata\.json/,
    resolve: "./metadata.json",
  },
  {
    pattern: /^\/dog-photos\/.*/,
    resolve: ([match]) => path.join("..", "dog-photos", match),
  },
  {
    pattern: /^\/author-photos\/(.*)/,
    resolve: (groups) => path.join("..", "authors", groups[1]) + ".jpg",
  },
]);

export default defineConfig({
  plugins: [serveStaticPlugin],
});

Config

The configuration is defined as an array of objects defining which patterns to intercept and how to resolve them.

Each pattern is defined as a regular expression. The resolve property can either be a string containing the path to a single file or a function that returns a string given the result of executing the pattern against the request path.

License

Licensed under the MIT License.

Keywords

FAQs

Package last updated on 04 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts