1.0.0 • Published 8 months ago

vite-plugin-nodemon v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Vite-Plugin-Nodemon

Run a backend server in a Vite project via Nodemon.

Usage

Install the plugin as you would any other Vite plugin:

In vite.config.js:

import {defineConfig} from 'vite';

export default defineConfig({
    plugins: [
		pluginNodemon({
			script: './server.js',
			watch: [
				'.env',
				'package.json',
				'server.js',
				'src/' + '**' + '/*.js', // Watch all JS files (we split the string up like this because those charcaters together can sometimes upset linters)
			],
			ignore: [
				'src/main.js', // Ignore the Vite main file
			],
            envInject: { // Inject these environment variables into both Vite + the process
            },
			envInjectVite: { // Inject these environment variables into Vite
				VITE_API_URL_BASE: 'http://localhost:8080',
			},
			envInjectProcess: { // Inject these environment variables into the process
				SERVER_HOST: 'localhost',
				SERVER_PORT: 8080,
			},
		}),
    ],
});

API

This NPM exposes a single function which returns a Vite plugin.

The function takes the following options:

OptionTypeDefaultDescription
scriptStringFile entrypoint to run as the server
delay=250Number250Delay between restarts when noticing a file change
watchArray<String> / StringArray (or single) glob of files to react to
ignoreArray<String> / String(or single) glob of files to ignore
envInjectObjectAdditional ENV variables to inject into both the outer VITE process + inner process when running in Nodemon mode
envInjectViteObjectAdditional ENV variables to inject into the outer Vite instance when running in Nodemon mode
envInjectProcessObjectAdditional ENV variables to inject into the inner instance when running in Nodemon mode
onStartFunctionFunction to run on initial boot. Called as ()
onRestartFunctionFunction to run on subsequent restarts. Called as (filesChanged:Array)
onQuitFunctionFunction to run on Nodemon quit. Called as ()
onLogFunctionFunction to run when Nodemon outputs log entries. Called as (logEntry:Object)
1.0.0

8 months ago