Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/reifiedbeans/vite-plugin-serve-static
Serve static files during local development
https://github.com/reifiedbeans/vite-plugin-serve-static
vite-plugin
Last synced: 3 months ago
JSON representation
Serve static files during local development
- Host: GitHub
- URL: https://github.com/reifiedbeans/vite-plugin-serve-static
- Owner: reifiedbeans
- License: mit
- Created: 2023-12-23T09:03:06.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-16T06:05:53.000Z (6 months ago)
- Last Synced: 2024-09-16T08:14:31.566Z (5 months ago)
- Topics: vite-plugin
- Language: TypeScript
- Homepage:
- Size: 110 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- fucking-awesome-vite - vite-plugin-serve-static - Allows serving arbitrary static files not in the `public/` directory. (Plugins / Framework-agnostic Plugins)
- awesome-vite - vite-plugin-serve-static - Allows serving arbitrary static files not in the `public/` directory. (Plugins / Framework-agnostic Plugins)
README
# vite-plugin-serve-static
[![npm](https://img.shields.io/npm/v/vite-plugin-serve-static/latest)](https://www.npmjs.com/package/vite-plugin-serve-static)
[![vite](https://img.shields.io/npm/dependency-version/vite-plugin-serve-static/peer/vite)](https://github.com/vitejs/vite)
[![license: MIT](https://img.shields.io/npm/l/vite-plugin-serve-static)](https://github.com/reifiedbeans/vite-plugin-serve-static/blob/main/LICENSE)A simple Vite plugin for serving arbitrary static files that aren't in your `public` directory.
```typescript
// 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](https://github.com/reifiedbeans/vite-plugin-serve-static/blob/main/LICENSE).
[regular expression]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp