1- import { defineConfig , splitVendorChunkPlugin } from 'vite' ;
2- import react from '@vitejs/plugin-react' ;
3- import checker from 'vite-plugin-checker' ;
1+ import { defineConfig , splitVendorChunkPlugin } from "vite" ;
2+ import react from "@vitejs/plugin-react" ;
3+ import checker from "vite-plugin-checker" ;
4+ import legacy from "@vitejs/plugin-legacy" ;
5+
6+
7+ const addScriptCSPNoncePlaceholderPlugin = ( ) => {
8+ return {
9+ name : "add-script-nonce-placeholderP-plugin" ,
10+ apply : "build" ,
11+ transformIndexHtml : {
12+ order : "post" ,
13+ handler ( htmlData ) {
14+
15+ return htmlData . replaceAll (
16+ / < s c r i p t n o m o d u l e > / gi,
17+ `<script nomodule nonce="__CSP_NONCE__">`
18+ ) . replaceAll (
19+ / < s c r i p t t y p e = " m o d u l e " > / gi,
20+ `<script type="module" nonce="__CSP_NONCE__">`
21+ ) . replaceAll (
22+ / < s c r i p t n o m o d u l e c r o s s o r i g i n i d = " v i t e - l e g a c y - e n t r y " / gi,
23+ `<script nomodule crossorigin id="vite-legacy-entry" nonce="__CSP_NONCE__"`
24+ ) ;
25+ } ,
26+ } ,
27+ } ;
28+ } ;
429
530export default defineConfig ( ( env ) => {
631 return {
@@ -23,13 +48,18 @@ export default defineConfig((env) => {
2348 } ,
2449 plugins : [
2550 react ( ) ,
26- env . mode !== 'test' && checker ( {
27- typescript : true ,
28- eslint : {
29- lintCommand : 'eslint --max-warnings=0 src' ,
30- } ,
51+ legacy ( {
52+ targets : [ 'edge 18' ] ,
3153 } ) ,
54+ env . mode !== "test" &&
55+ checker ( {
56+ typescript : true ,
57+ eslint : {
58+ lintCommand : 'eslint --max-warnings=0 src' ,
59+ } ,
60+ } ) ,
3261 splitVendorChunkPlugin ( ) ,
62+ addScriptCSPNoncePlaceholderPlugin ( ) ,
3363 ] ,
3464 test : {
3565 globals : true ,
0 commit comments