0.1.4 • Published 6 months ago

@neondatabase/vite-plugin-postgres v0.1.4

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
6 months ago

Vite-Plugin-Postgres by Neon

This Vite plugin instantly provisions a Postgres instance (via Neon) and injects the connection string into your .env file, so you can start developing immediately.

How it works

  • On first vite dev, the plugin checks for a DATABASE_URL (or your configured key) in your .env.
  • If not found, it creates a claimable Neon database and writes the connection string to your .env.
  • The plugin is a noop in production builds.

Installation

npm add @neondatabase/vite-plugin-postgres

Usage

Add the plugin as the first entry in your Vite config:

import postgresPlugin from "@neondatabase/vite-plugin-postgres";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";

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

Configuration

You can pass an options object to customize the .env file path and the environment variable name:

postgresPlugin({
	env: ".env.local", // Path to your .env file (default: ".env")
	envKey: "DATABASE_URL", // Name of the env variable (default: "DATABASE_URL")
});
OptionTypeDescriptionDefault
envstringPath to the .env file.env
envKeystringName of the environment variableDATABASE_URL

What gets written

  • The plugin writes both a direct connection string and a pooled connection string to your .env.
  • It also provides a claim URL (valid for 7 days) to take ownership of the database.

Type Definitions

interface PostgresPluginOptions {
	env: string; // Path to the .env file
	envKey: string; // Name of the environment variable
}

FAQ

The plugin is a noop in production mode (vite build), so it won't create databases or modify your .env in CI.

Yes, this plugin is framework-agnostic. The example uses React, but you can use it with any Vite-compatible framework.

Advanced

If you want to generate claimable databases outside of Vite, use the neondb library directly.

See documentation on Neon for more.

0.1.4

6 months ago

0.1.3

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

8 months ago

0.0.1

8 months ago