https://github.com/jrtderonde/vite-create-production-server-plugin
  
  
     
    https://github.com/jrtderonde/vite-create-production-server-plugin
  
        Last synced: 6 months ago 
        JSON representation
    
- Host: GitHub
 - URL: https://github.com/jrtderonde/vite-create-production-server-plugin
 - Owner: jrtderonde
 - Created: 2024-10-30T07:22:30.000Z (about 1 year ago)
 - Default Branch: master
 - Last Pushed: 2024-11-06T13:52:52.000Z (12 months ago)
 - Last Synced: 2025-04-11T22:45:50.808Z (7 months ago)
 - Language: TypeScript
 - Size: 176 KB
 - Stars: 0
 - Watchers: 1
 - Forks: 0
 - Open Issues: 0
 - 
            Metadata Files:
            
- Readme: README.md
 
 
Awesome Lists containing this project
- fucking-awesome-vite - vite-create-production-server-plugin - Spin up a production HTTP serve after build. (Plugins / Framework-agnostic Plugins)
 - awesome-vite - vite-create-production-server-plugin - Spin up a production HTTP serve after build. (Plugins / Framework-agnostic Plugins)
 
README
          # `vite-create-production-server-plugin`
A Vite plugin to create a production-ready static file server for your built assets. This plugin simplifies serving files directly from the `dist` folder without needing an additional server setup. You can configure the port, entry point, and build directory as needed.
## Installation
To install the plugin, run:
```bash
npm install vite-create-production-server-plugin serve-static --save-dev
```
## Usage
Add the plugin to your `vite.config.ts` (or `vite.config.js`) file:
```typescript
import { defineConfig } from "vite";
import { createProductionServerPlugin } from "vite-create-production-server-plugin";
export default defineConfig({
  plugins: [
    createProductionServerPlugin({
      port: 3000, // Optional, default is 8080
      entryPoint: "index.html", // Optional, default is "index.html"
      buildDirectory: "dist", // Optional, default is "dist"
    }),
  ],
});
```
## Options
The plugin accepts an options object to configure the server:
- `port` (number, optional): Port number on which the server will run. Default is `8080`.
- `entryPoint` (string, optional): The entry HTML file to serve. Default is `"index.html"`.
- `buildDirectory` (string, optional): Directory to serve static files from. Default is `"dist"`.
### Example
```typescript
createProductionServerPlugin({
  port: 5000,
  entryPoint: "main.html",
  buildDirectory: "output",
});
```
## Running the Server
Use the `--serve` or `-s` command-line argument to start the production server after building:
```bash
vite build -- --serve
```
or
```bash
vite build -- -s
```
The server will start on the configured port (`http://localhost:`), and it will automatically clear the console for easier readability. This plugin is perfect for serving static files without the need for a separate server or complex configuration.