A Vite plugin that lets SPA applications generate a Content Security Policy (CSP).
npm install vite-plugin-csp-guardbash
npm install -D vite-plugin-csp-guard
or
yarn add -D vite-plugin-csp-guard
or
pnpm add -D vite-plugin-csp-guard
`
Basic Usage
`ts
// vite.config.ts
import { defineConfig } from "vite";
import csp from "vite-plugin-csp-guard";
export default defineConfig({
plugins: [
csp({
algorithm: "sha256", // The algorithm to use for hashing
dev: {
run: true, // If you want to run the plugin in vite dev mode
},
policy: {
// Specify the policy here.
"script-src": ["'self'", "https://www.google-analytics.com"], // Example: Allow Google Analytics
"style-src": ["'self'", "https://fonts.googleapis.com"], // Example: Allow Google Fonts
},
}),
],
});
``