Registry / web-framework / vite-plugin-auto-origin

vite-plugin-auto-origin

JSON →
library2.0.2jsnpmunverified

A Vite plugin that automatically configures server.origin to the external URL of the Vite dev server, essential for backend integration scenarios where assets (images, fonts) must be loaded from the dev server URL rather than the backend. Version 2.0.2 supports Vite 5+, ships TypeScript types, and is ESM-only since v2. Active maintenance with frequent updates aligned with Vite major releases. Differentiator: handles proxy chains automatically without manual configuration.

npm install vite-plugin-auto-origin
INSTALL
IMPORT
SIG · VITE-PLUGIN-AUTO-O
V
vite-plugin-auto-origin
web-frameworkjavascriptv2.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

autoOrigin
import autoOrigin from 'vite-plugin-auto-origin'
const autoOrigin = require('vite-plugin-auto-origin')
Default export, ESM-only since v2. CommonJS require will fail.
AutoOriginOptions
import type { AutoOriginOptions } from 'vite-plugin-auto-origin'
Type import for TypeScript users.
Plugin
import type { Plugin } from 'vite'; import autoOrigin from 'vite-plugin-auto-origin'; const plugin: Plugin = autoOrigin()
const plugin = autoOrigin; (missing function call)
autoOrigin is a factory function that returns a Vite Plugin object.

Install the plugin and add it to the Vite config. The server.origin will be automatically set to the external URL of the dev server.

import { defineConfig } from 'vite'; import autoOrigin from 'vite-plugin-auto-origin'; export default defineConfig({ plugins: [autoOrigin()], // server.origin will be set automatically });
Debug
Known issues
breakingVersion 2.0.0 drops CommonJS support. The package is ESM-only.
fix
Use import/ESM syntax. If CJS is required, stick to v1.x.
affects: >=2.0.0
deprecatedVite 5 is the minimum supported version in v2.x. Older Vite versions are not supported.
fix
Upgrade Vite to ^5.0 || ^6.0 || ^7.0 || ^8.0
affects: >=2.0.0
gotchaThe plugin does not work with Vite 4 or earlier. Ensure Vite version is compatible.
fix
Use vite-plugin-auto-origin@1.x for Vite 4, or upgrade Vite to 5+.
affects: >=1.0.0
gotchaIn some proxy configurations, the plugin may detect the internal proxy URL instead of the external URL. Manual override via options may be needed.
fix
Pass options to autoOrigin({ origin: 'https://your-external-url' }) to force the origin.
affects: >=1.0.0
Errors
Common errors & fixes
require() of ES Module /node_modules/vite-plugin-auto-origin/dist/index.js from /project/vite.config.js not supported.
Using CommonJS require() on an ESM-only package (v2+).
fix
Change to import statement or downgrade to v1.x.
TypeError: autoOrigin is not a function
Calling autoOrigin as a value without parentheses, or importing incorrectly.
fix
Use autoOrigin() (call the factory function) in the plugins array.
Error: The plugin 'vite-plugin-auto-origin' requires Vite >=5.0.0
Installing v2.x with an older Vite version.
fix
Upgrade Vite to ^5.0 || ^6.0 || ^7.0 || ^8.0 or install v1.x (npm install vite-plugin-auto-origin@1).
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies
viterequiredPeer dependency; plugin requires Vite 5, 6, 7, or 8
Agent activity
8 hits · last 30 days
node
6
OpenAI (training)
2
Resources
vite-plugin-auto-origin — npm install vite-plugin-auto-origin · libregistry