1 import { defineConfig } from 'vite';
2 import mkcert from 'vite-plugin-mkcert';
3 import { viteSingleFile } from 'vite-plugin-singlefile';
5 export default defineConfig({
9 // this is required for the SCSS modules
19 name: 'html-inject-nonce-into-script-tag',
22 * Adds template for nonce that can be later replaced by the host of the HTML file.
23 * Backend is supposed to return this file as-is with the exception of replacing "{nonce}"".
25 transformIndexHtml(html: string) {
26 const scriptStartRegex = /<script(.*?)/gi;
27 const nonce = '<script nonce="{nonce}"$1';
29 return html.replace(scriptStartRegex, nonce);
34 * This allows to dynamically replace the JS script on the backend. It's helpful for debugging
35 * in development, especially when the script is being served from a different domain.
37 name: 'html-replace-chargebee-js-src',
39 transformIndexHtml(html: string) {
40 if (process.env.NODE_ENV !== 'production') {
44 const srcRegex = /src="(.*?chargebee.*?)"/gi;
45 const chargebeeTemplate = 'src="{chargebee_js_src}"';
47 return html.replace(srcRegex, chargebeeTemplate);