diff --git a/packages/sui-ssr/bin/sui-ssr-dev.js b/packages/sui-ssr/bin/sui-ssr-dev.js index 5650c4da1..305a92699 100644 --- a/packages/sui-ssr/bin/sui-ssr-dev.js +++ b/packages/sui-ssr/bin/sui-ssr-dev.js @@ -3,6 +3,7 @@ const program = require('commander') const {exec} = require('child_process') +const {cp} = require('fs/promises') const path = require('path') const fs = require('fs') const express = require('express') @@ -19,6 +20,8 @@ const log = require('@s-ui/bundler/shared/log.js') const serverConfigFactory = require('../compiler/server.js') const TMP_PATH = '.sui' +const SRC_PATH = path.join(process.cwd(), 'src') +const PUBLIC_OUTPUT_PATH = path.join(process.cwd(), `${TMP_PATH}/public`) const SERVER_OUTPUT_PATH = path.join(process.cwd(), `${TMP_PATH}/server`) const STATICS_PATH = path.join(process.cwd(), './statics') const STATICS_OUTPUT_PATH = path.join(process.cwd(), `${TMP_PATH}/statics`) @@ -63,6 +66,13 @@ const linkStatics = () => { ) } +const copyStatics = () => { + return Promise.allSettled([ + cp(path.join(SRC_PATH, '404.html'), path.join(PUBLIC_OUTPUT_PATH, '404.html'), {recursive: true}), + cp(path.join(SRC_PATH, '500.html'), path.join(PUBLIC_OUTPUT_PATH, '500.html'), {recursive: true}) + ]) +} + const initMSW = () => { return exec(`npx msw init ${STATICS_PATH}`) } @@ -153,7 +163,13 @@ const start = async ({packagesToLink, linkAll}) => { fs.mkdirSync(TMP_PATH) } - Promise.all([linkStatics(), initMSW(), compile('client', clientCompiler), compile('server', serverCompiler)]) + Promise.all([ + linkStatics(), + initMSW(), + copyStatics(), + compile('client', clientCompiler), + compile('server', serverCompiler) + ]) .then(() => { const script = nodemon({ script: `${SERVER_OUTPUT_PATH}/index.js`,