diff --git a/.changeset/quick-balloons-invite.md b/.changeset/quick-balloons-invite.md new file mode 100644 index 000000000000..c4df6a5caa55 --- /dev/null +++ b/.changeset/quick-balloons-invite.md @@ -0,0 +1,5 @@ +--- +'create-svelte': patch +--- + +create-svelte: bundle production dependencies for SSR diff --git a/.changeset/weak-swans-lie.md b/.changeset/weak-swans-lie.md new file mode 100644 index 000000000000..3a6a9b541ba0 --- /dev/null +++ b/.changeset/weak-swans-lie.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +kit: bundle @sveltejs/kit into built application diff --git a/examples/hn.svelte.dev/vite.config.js b/examples/hn.svelte.dev/vite.config.js index 4c52b8079c75..499379c8130d 100644 --- a/examples/hn.svelte.dev/vite.config.js +++ b/examples/hn.svelte.dev/vite.config.js @@ -1,9 +1,18 @@ -import { resolve } from 'path'; +// Consult https://vitejs.dev/config/ to learn about these options +import { join, resolve } from 'path'; +import { readFileSync } from 'fs'; +import { cwd } from 'process'; +const pkg = JSON.parse(readFileSync(join(cwd(), 'package.json'))); + +/** @type {import('vite').UserConfig} */ export default { resolve: { alias: { $components: resolve('src/components') } + }, + ssr: { + noExternal: Object.keys(pkg.dependencies || {}) } }; diff --git a/examples/realworld.svelte.dev/vite.config.js b/examples/realworld.svelte.dev/vite.config.js index ad6f3c58cda6..258a5294921c 100644 --- a/examples/realworld.svelte.dev/vite.config.js +++ b/examples/realworld.svelte.dev/vite.config.js @@ -1,10 +1,19 @@ -import { resolve } from 'path'; +// Consult https://vitejs.dev/config/ to learn about these options +import { join, resolve } from 'path'; +import { readFileSync } from 'fs'; +import { cwd } from 'process'; +const pkg = JSON.parse(readFileSync(join(cwd(), 'package.json'))); + +/** @type {import('vite').UserConfig} */ export default { resolve: { alias: { $common: resolve('src/common'), $components: resolve('src/components') } + }, + ssr: { + noExternal: Object.keys(pkg.dependencies || {}) } }; diff --git a/examples/sandbox/vite.config.js b/examples/sandbox/vite.config.js index 7fd500d16c9a..4d8a2e7a2386 100644 --- a/examples/sandbox/vite.config.js +++ b/examples/sandbox/vite.config.js @@ -1,5 +1,11 @@ -import { resolve } from 'path'; +// Consult https://vitejs.dev/config/ to learn about these options +import { join, resolve } from 'path'; +import { readFileSync } from 'fs'; +import { cwd } from 'process'; +const pkg = JSON.parse(readFileSync(join(cwd(), 'package.json'))); + +/** @type {import('vite').UserConfig} */ export default { build: { minify: false @@ -8,5 +14,8 @@ export default { alias: { $components: resolve('src/components') } + }, + ssr: { + noExternal: Object.keys(pkg.dependencies || {}) } }; diff --git a/examples/svelte-kit-demo/vite.config.js b/examples/svelte-kit-demo/vite.config.js index 4c52b8079c75..499379c8130d 100644 --- a/examples/svelte-kit-demo/vite.config.js +++ b/examples/svelte-kit-demo/vite.config.js @@ -1,9 +1,18 @@ -import { resolve } from 'path'; +// Consult https://vitejs.dev/config/ to learn about these options +import { join, resolve } from 'path'; +import { readFileSync } from 'fs'; +import { cwd } from 'process'; +const pkg = JSON.parse(readFileSync(join(cwd(), 'package.json'))); + +/** @type {import('vite').UserConfig} */ export default { resolve: { alias: { $components: resolve('src/components') } + }, + ssr: { + noExternal: Object.keys(pkg.dependencies || {}) } }; diff --git a/packages/create-svelte/template/vite.config.js b/packages/create-svelte/template/vite.config.js index c24a94e3740d..499379c8130d 100644 --- a/packages/create-svelte/template/vite.config.js +++ b/packages/create-svelte/template/vite.config.js @@ -1,5 +1,9 @@ // Consult https://vitejs.dev/config/ to learn about these options -import { resolve } from 'path'; +import { join, resolve } from 'path'; +import { readFileSync } from 'fs'; +import { cwd } from 'process'; + +const pkg = JSON.parse(readFileSync(join(cwd(), 'package.json'))); /** @type {import('vite').UserConfig} */ export default { @@ -7,5 +11,8 @@ export default { alias: { $components: resolve('src/components') } + }, + ssr: { + noExternal: Object.keys(pkg.dependencies || {}) } }; diff --git a/packages/kit/src/core/build/index.js b/packages/kit/src/core/build/index.js index e405fc2ba9cd..c8f5cee7e3b4 100644 --- a/packages/kit/src/core/build/index.js +++ b/packages/kit/src/core/build/index.js @@ -379,7 +379,8 @@ async function build_server( name: 'app', formats: ['es'] }, - outDir: `${output_dir}/server` + outDir: `${output_dir}/server`, + target: 'es2018' }, resolve: { alias: { @@ -398,7 +399,7 @@ async function build_server( }) ], ssr: { - noExternal: ['svelte'] + noExternal: ['svelte', '@sveltejs/kit'] }, optimizeDeps: { entries: []