Registry / auth-security / vite-shield

vite-shield

JSON →
library1.0.0jsnpmunverified

Vite-Shield is a zero-configuration CLI tool that automatically adds comprehensive security headers to Vite/React projects. Version 1.0.0 integrates security headers into Vite's dev and preview servers, generates a production-ready Express.js server with helmet-style headers, and creates an Nginx configuration template. Unlike manual header setup or using helmet separately, Vite-Shield provides a one-command solution using AST-based transformations to safely modify vite.config.ts/js without breaking existing setups. It applies headers like Strict-Transport-Security, CSP, X-Frame-Options, and more across all environments.

npm install vite-shield
INSTALL
IMPORT
SIG · VITE-SHIELD
V
vite-shield
auth-securityjavascriptv1.0.0
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.

vite-shield
npx vite-shield
import viteShield from 'vite-shield'
CLI tool only, no programmatic API available
vite.config
export default defineConfig({ server: { headers: {} } })
module.exports = { server: { headers: {} } }
Vite config must use ESM export syntax

Shows how to install and run vite-shield via global install or npx, then start the generated Express server.

# Navigate to your Vite/React project cd my-vite-project # Install vite-shield globally or use npx npm install -g vite-shield vite-shield # Alternatively, with npx (no install): npx vite-shield # After running, vite.config.ts/js is updated with security headers. # A production server.js and nginx.conf are also created. # To start the production server: npm install --save-dev express node server.js
vite-shield --version
Debug
Known issues
gotchaRunning vite-shield overwrites any existing security headers in vite.config.ts/js without merging
fix
Manually back up your vite.config before running vite-shield
affects: >=1.0.0
gotchavite-shield modifies vite.config.ts/js using AST; if your config uses unusual syntax or plugins that generate dynamic headers, the tool may produce invalid config
fix
Review the generated config and manually adjust if needed
affects: >=1.0.0
gotchaThe generated server.js uses ESM imports (import express from 'express') which requires "type": "module" in package.json or .mjs extension
fix
Add "type": "module" to package.json or rename server.js to server.mjs
affects: >=1.0.0
gotchaThe generated nginx.conf uses add_header directives that may conflict with existing server blocks if not placed in the correct context
fix
Ensure the add_header directives are inside the server block and not duplicated
affects: >=1.0.0
Errors
Common errors & fixes
Command 'vite-shield' not found
vite-shield not installed globally or path not set
fix
Use npx vite-shield or npm install -g vite-shield
Cannot find module '/path/to/project/vite.config.ts'
Command not run from the root of a Vite project
fix
cd to the directory containing vite.config.ts or vite.config.js before running
error: unknown option '--something'
vite-shield has no CLI options; extra flags cause errors
fix
Run vite-shield with no arguments
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
viterequiredrequired to modify vite.config file and apply headers
Agent activity
26 hits · last 30 days
node
20
OpenAI (training)
1
Resources
vite-shield — npm install vite-shield · libregistry