From b47c592e39e29df06ce39ed0c25094d915a423e3 Mon Sep 17 00:00:00 2001 From: Ahad Birang Date: Thu, 9 Sep 2021 14:25:40 +0430 Subject: [PATCH] fix(nitro): do not overwrite output files for browser-preset (#516) --- packages/nitro/src/presets/browser.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/nitro/src/presets/browser.ts b/packages/nitro/src/presets/browser.ts index 6bfc04928c..ee52d8f074 100644 --- a/packages/nitro/src/presets/browser.ts +++ b/packages/nitro/src/presets/browser.ts @@ -1,4 +1,4 @@ -import { writeFile } from 'fs-extra' +import { existsSync, writeFile } from 'fs-extra' import { resolve } from 'upath' import consola from 'consola' import { extendPreset, prettyPath } from '../utils' @@ -68,10 +68,15 @@ if ('serviceWorker' in navigator) { await writeFile(resolve(output.publicDir, 'sw.js'), `self.importScripts('${input._nuxt.routerBase}_server/index.mjs');`) // Temp fix - await writeFile(resolve(output.publicDir, 'index.html'), html) - await writeFile(resolve(output.publicDir, '200.html'), html) - await writeFile(resolve(output.publicDir, '404.html'), html) - + if (!existsSync(resolve(output.publicDir, 'index.html'))) { + await writeFile(resolve(output.publicDir, 'index.html'), html) + } + if (!existsSync(resolve(output.publicDir, '200.html'))) { + await writeFile(resolve(output.publicDir, '200.html'), html) + } + if (!existsSync(resolve(output.publicDir, '404.html'))) { + await writeFile(resolve(output.publicDir, '404.html'), html) + } consola.info('Ready to deploy to static hosting:', prettyPath(output.publicDir as string)) } }