From 506f9d2892501e103610b75ddbc0d3e931c72f13 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 20 May 2024 17:14:48 -0400 Subject: [PATCH] add pnpm prod command to playground (#11697) --- .gitignore | 1 - playgrounds/demo/.gitignore | 3 ++- playgrounds/demo/dist/index.js | 22 ++++++++++++++++++++++ playgrounds/demo/package.json | 3 ++- playgrounds/demo/vite.config.js | 3 +++ 5 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 playgrounds/demo/dist/index.js diff --git a/.gitignore b/.gitignore index 16cac3b27f..4ce5c243c7 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,6 @@ coverage .env.test # build output -dist .vercel # OS-specific diff --git a/playgrounds/demo/.gitignore b/playgrounds/demo/.gitignore index 13c523dea0..3653d28870 100644 --- a/playgrounds/demo/.gitignore +++ b/playgrounds/demo/.gitignore @@ -1,4 +1,5 @@ src/* -dist/* +dist/client/* +dist/server/* !src/entry-client.ts !src/entry-server.ts diff --git a/playgrounds/demo/dist/index.js b/playgrounds/demo/dist/index.js new file mode 100644 index 0000000000..4aa70d0f14 --- /dev/null +++ b/playgrounds/demo/dist/index.js @@ -0,0 +1,22 @@ +import fs from 'node:fs'; +import path from 'node:path'; +import express from 'express'; +import { head, html } from './server/entry-server.js'; + +const rendered = fs + .readFileSync(path.resolve('./dist/client/index.html'), 'utf-8') + .replace(``, html) + .replace(``, head); + +express() + .use('*', async (req, res) => { + if (req.originalUrl !== '/') { + res.sendFile(path.resolve('./dist/client' + req.originalUrl)); + return; + } + + res.status(200).set({ 'Content-Type': 'text/html' }).end(rendered); + }) + .listen('3000'); + +console.log('listening on http://localhost:3000'); diff --git a/playgrounds/demo/package.json b/playgrounds/demo/package.json index 7f0c920d0f..e96e8011ba 100644 --- a/playgrounds/demo/package.json +++ b/playgrounds/demo/package.json @@ -7,7 +7,8 @@ "prepare": "node scripts/create-app-svelte.js", "dev": "vite --host", "ssr": "node ./server.js", - "build": "vite build", + "build": "vite build --outDir dist/client && vite build --outDir dist/server --ssr src/entry-server.ts", + "prod": "npm run build && node dist", "preview": "vite preview" }, "devDependencies": { diff --git a/playgrounds/demo/vite.config.js b/playgrounds/demo/vite.config.js index a6a970e8cd..0feb57810d 100644 --- a/playgrounds/demo/vite.config.js +++ b/playgrounds/demo/vite.config.js @@ -3,6 +3,9 @@ import inspect from 'vite-plugin-inspect'; import { svelte } from '@sveltejs/vite-plugin-svelte'; export default defineConfig({ + build: { + minify: false + }, plugins: [inspect(), svelte()], optimizeDeps: { // svelte is a local workspace package, optimizing it would require dev server restarts with --force for every change