@@ -36,31 +36,36 @@ if (!certificateName) {
3636const certFilePath = path . join ( baseFolder , `${ certificateName } .pem` ) ;
3737const keyFilePath = path . join ( baseFolder , `${ certificateName } .key` ) ;
3838
39- console . log ( `Certificate path: ${ certFilePath } ` ) ;
39+ // Only generate certificates for dev server, not for build
40+ const isDevServer = ! process . argv . includes ( 'build' ) ;
4041
41- if ( ! fs . existsSync ( certFilePath ) || ! fs . existsSync ( keyFilePath ) ) {
42+ if ( isDevServer ) {
43+ console . log ( `Certificate path: ${ certFilePath } ` ) ;
4244
43- // mkdir to fix dotnet dev-certs error 3 https://github.com/dotnet/aspnetcore/issues/58330
44- if ( ! fs . existsSync ( baseFolder ) ) {
45- fs . mkdirSync ( baseFolder , { recursive : true } ) ;
46- }
47- if (
48- 0 !==
49- child_process . spawnSync (
50- "dotnet" ,
51- [
52- "dev-certs" ,
53- "https" ,
54- "--export-path" ,
55- certFilePath ,
56- "--format" ,
57- "Pem" ,
58- "--no-password" ,
59- ] ,
60- { stdio : "inherit" }
61- ) . status
62- ) {
63- throw new Error ( "Could not create certificate." ) ;
45+ if ( ! fs . existsSync ( certFilePath ) || ! fs . existsSync ( keyFilePath ) ) {
46+
47+ // mkdir to fix dotnet dev-certs error 3 https://github.com/dotnet/aspnetcore/issues/58330
48+ if ( ! fs . existsSync ( baseFolder ) ) {
49+ fs . mkdirSync ( baseFolder , { recursive : true } ) ;
50+ }
51+ if (
52+ 0 !==
53+ child_process . spawnSync (
54+ "dotnet" ,
55+ [
56+ "dev-certs" ,
57+ "https" ,
58+ "--export-path" ,
59+ certFilePath ,
60+ "--format" ,
61+ "Pem" ,
62+ "--no-password" ,
63+ ] ,
64+ { stdio : "inherit" }
65+ ) . status
66+ ) {
67+ throw new Error ( "Could not create certificate." ) ;
68+ }
6469 }
6570}
6671
@@ -100,7 +105,7 @@ export default defineConfig(async () => {
100105 tailwindcss ( ) ,
101106 Press ( {
102107 baseUrl,
103- //Uncomment to generate metadata *.json
108+ //Uncomment to generate metadata *.json
104109 //metadataPath: './public/api',
105110 } ) ,
106111 ] ,
@@ -109,6 +114,9 @@ export default defineConfig(async () => {
109114 '@' : fileURLToPath ( new URL ( './src' , import . meta. url ) ) ,
110115 }
111116 } ,
117+ build : {
118+ target : 'baseline-widely-available' ,
119+ } ,
112120 server : {
113121 proxy : {
114122 '^/api' : {
@@ -117,10 +125,12 @@ export default defineConfig(async () => {
117125 }
118126 } ,
119127 port : 5173 ,
120- https : {
121- key : fs . readFileSync ( keyFilePath ) ,
122- cert : fs . readFileSync ( certFilePath ) ,
123- }
128+ ...( fs . existsSync ( keyFilePath ) && fs . existsSync ( certFilePath ) ? {
129+ https : {
130+ key : fs . readFileSync ( keyFilePath ) ,
131+ cert : fs . readFileSync ( certFilePath ) ,
132+ }
133+ } : { } )
124134 }
125135 }
126136} )
0 commit comments