1 import { defineConfig } from 'vite';
2 import mkcert from 'vite-plugin-mkcert';
3 import { viteSingleFile } from 'vite-plugin-singlefile';
5 export default defineConfig({
10 name: 'html-inject-nonce-into-script-tag',
13 * Adds template for nonce that can be later replaced by the host of the HTML file.
14 * Backend is supposed to return this file as-is with the exception of replacing "{nonce}"".
16 transformIndexHtml(html: string) {
17 const scriptStartRegex = /<script(.*?)/gi;
18 const nonce = '<script nonce="{nonce}"$1';
20 return html.replace(scriptStartRegex, nonce);