From 7968431109030176415c3e149f876b9095e7a1e3 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 18 Mar 2021 17:31:30 -0400 Subject: [PATCH 1/7] retire vite.config.js in favour of config.kit.vite - fixes #509 --- examples/hn.svelte.dev/svelte.config.cjs | 2 -- examples/hn.svelte.dev/vite.config.js | 13 ---------- .../realworld.svelte.dev/svelte.config.cjs | 8 +++++- examples/realworld.svelte.dev/vite.config.js | 13 ---------- examples/sandbox/svelte.config.cjs | 17 +++++++----- examples/sandbox/vite.config.js | 16 ------------ examples/svelte-kit-demo/svelte.config.cjs | 5 ---- examples/svelte-kit-demo/vite.config.js | 13 ---------- .../create-svelte/template/svelte.config.cjs | 10 ++++++- .../create-svelte/template/vite.config.js | 13 ---------- packages/kit/src/core/build/index.js | 26 ++++++++++++++++++- packages/kit/src/core/dev/index.js | 9 +++++++ .../kit/src/core/load_config/index.spec.js | 6 +++++ packages/kit/src/core/load_config/options.js | 21 ++++++++++++++- .../kit/src/core/load_config/test/index.js | 2 ++ .../kit/test/apps/basics/svelte.config.cjs | 10 ++++--- packages/kit/test/apps/basics/vite.config.js | 6 ----- .../test/apps/custom-extension/vite.config.js | 5 ---- .../kit/test/apps/options/svelte.config.cjs | 13 +++++----- packages/kit/test/apps/options/vite.config.js | 6 ----- packages/kit/types.internal.d.ts | 1 + 21 files changed, 104 insertions(+), 111 deletions(-) delete mode 100644 examples/hn.svelte.dev/vite.config.js delete mode 100644 examples/realworld.svelte.dev/vite.config.js delete mode 100644 examples/sandbox/vite.config.js delete mode 100644 examples/svelte-kit-demo/vite.config.js delete mode 100644 packages/create-svelte/template/vite.config.js delete mode 100644 packages/kit/test/apps/basics/vite.config.js delete mode 100644 packages/kit/test/apps/custom-extension/vite.config.js delete mode 100644 packages/kit/test/apps/options/vite.config.js diff --git a/examples/hn.svelte.dev/svelte.config.cjs b/examples/hn.svelte.dev/svelte.config.cjs index 6d3ecf4d72bb..97ab0912e10c 100644 --- a/examples/hn.svelte.dev/svelte.config.cjs +++ b/examples/hn.svelte.dev/svelte.config.cjs @@ -1,8 +1,6 @@ module.exports = { kit: { adapter: '@sveltejs/adapter-netlify', - - // hydrate the
element in src/app.html target: '#svelte' } }; diff --git a/examples/hn.svelte.dev/vite.config.js b/examples/hn.svelte.dev/vite.config.js deleted file mode 100644 index c466de9ae4a6..000000000000 --- a/examples/hn.svelte.dev/vite.config.js +++ /dev/null @@ -1,13 +0,0 @@ -// Consult https://vitejs.dev/config/ to learn about these options -import { join } 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 { - ssr: { - noExternal: Object.keys(pkg.dependencies || {}) - } -}; diff --git a/examples/realworld.svelte.dev/svelte.config.cjs b/examples/realworld.svelte.dev/svelte.config.cjs index d41b7d971683..cbc68667c87f 100644 --- a/examples/realworld.svelte.dev/svelte.config.cjs +++ b/examples/realworld.svelte.dev/svelte.config.cjs @@ -6,6 +6,12 @@ module.exports = { adapter: '@sveltejs/adapter-node', // hydrate the
element in src/app.html - target: '#svelte' + target: '#svelte', + + vite: { + ssr: { + noExternal: ['node-fetch'] + } + } } }; diff --git a/examples/realworld.svelte.dev/vite.config.js b/examples/realworld.svelte.dev/vite.config.js deleted file mode 100644 index c466de9ae4a6..000000000000 --- a/examples/realworld.svelte.dev/vite.config.js +++ /dev/null @@ -1,13 +0,0 @@ -// Consult https://vitejs.dev/config/ to learn about these options -import { join } 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 { - ssr: { - noExternal: Object.keys(pkg.dependencies || {}) - } -}; diff --git a/examples/sandbox/svelte.config.cjs b/examples/sandbox/svelte.config.cjs index d41b7d971683..c6e25e344c02 100644 --- a/examples/sandbox/svelte.config.cjs +++ b/examples/sandbox/svelte.config.cjs @@ -1,11 +1,16 @@ +const pkg = require('./package.json'); + module.exports = { kit: { - // By default, `npm run build` will create a standard Node app. - // You can create optimized builds for different platforms by - // specifying a different adapter adapter: '@sveltejs/adapter-node', - - // hydrate the
element in src/app.html - target: '#svelte' + target: '#svelte', + vite: { + build: { + minify: false + }, + ssr: { + noExternal: Object.keys(pkg.dependencies || {}) + } + } } }; diff --git a/examples/sandbox/vite.config.js b/examples/sandbox/vite.config.js deleted file mode 100644 index 537eb29a131a..000000000000 --- a/examples/sandbox/vite.config.js +++ /dev/null @@ -1,16 +0,0 @@ -// Consult https://vitejs.dev/config/ to learn about these options -import { join } 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 - }, - ssr: { - noExternal: Object.keys(pkg.dependencies || {}) - } -}; diff --git a/examples/svelte-kit-demo/svelte.config.cjs b/examples/svelte-kit-demo/svelte.config.cjs index d41b7d971683..a6405c66098a 100644 --- a/examples/svelte-kit-demo/svelte.config.cjs +++ b/examples/svelte-kit-demo/svelte.config.cjs @@ -1,11 +1,6 @@ module.exports = { kit: { - // By default, `npm run build` will create a standard Node app. - // You can create optimized builds for different platforms by - // specifying a different adapter adapter: '@sveltejs/adapter-node', - - // hydrate the
element in src/app.html target: '#svelte' } }; diff --git a/examples/svelte-kit-demo/vite.config.js b/examples/svelte-kit-demo/vite.config.js deleted file mode 100644 index c466de9ae4a6..000000000000 --- a/examples/svelte-kit-demo/vite.config.js +++ /dev/null @@ -1,13 +0,0 @@ -// Consult https://vitejs.dev/config/ to learn about these options -import { join } 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 { - ssr: { - noExternal: Object.keys(pkg.dependencies || {}) - } -}; diff --git a/packages/create-svelte/template/svelte.config.cjs b/packages/create-svelte/template/svelte.config.cjs index ce8d98bcb26c..39f28aef447e 100644 --- a/packages/create-svelte/template/svelte.config.cjs +++ b/packages/create-svelte/template/svelte.config.cjs @@ -1,3 +1,5 @@ +const pkg = require('./package.json'); + /** @type {import('@sveltejs/kit').Config} */ module.exports = { kit: { @@ -7,6 +9,12 @@ module.exports = { adapter: '@sveltejs/adapter-node', // hydrate the
element in src/app.html - target: '#svelte' + target: '#svelte', + + vite: { + ssr: { + noExternal: Object.keys(pkg.dependencies || {}) + } + } } }; diff --git a/packages/create-svelte/template/vite.config.js b/packages/create-svelte/template/vite.config.js deleted file mode 100644 index c466de9ae4a6..000000000000 --- a/packages/create-svelte/template/vite.config.js +++ /dev/null @@ -1,13 +0,0 @@ -// Consult https://vitejs.dev/config/ to learn about these options -import { join } 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 { - 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 5261fa1f45a1..4fcdac1c5d73 100644 --- a/packages/kit/src/core/build/index.js +++ b/packages/kit/src/core/build/index.js @@ -109,11 +109,15 @@ async function build_client({ }); }); - // client build + /** @type {any} */ + const user_config = config.kit.vite(); + await vite.build({ + ...user_config, root: cwd, base, build: { + ...user_config.build, cssCodeSplit: true, manifest: true, lib: { @@ -126,6 +130,7 @@ async function build_client({ }, outDir: client_out_dir, rollupOptions: { + ...(user_config.build && user_config.build.rollupOptions), input, output: { entryFileNames: '[name]-[hash].js', @@ -136,12 +141,15 @@ async function build_client({ } }, resolve: { + ...user_config.resolve, alias: { + ...(user_config.resolve && user_config.resolve.alias), $app: path.resolve(`${build_dir}/runtime/app`), $lib: config.kit.files.lib } }, plugins: [ + ...(user_config.plugins || []), svelte({ extensions: config.extensions }) @@ -370,10 +378,15 @@ async function build_server( .trim() ); + /** @type {any} */ + const user_config = config.kit.vite(); + await vite.build({ + ...user_config, root: cwd, base, build: { + ...user_config.build, ssr: true, lib: { entry: app_file, @@ -384,12 +397,15 @@ async function build_server( target: 'es2018' }, resolve: { + ...user_config.resolve, alias: { + ...(user_config.resolve && user_config.resolve.alias), $app: path.resolve(`${build_dir}/runtime/app`), $lib: config.kit.files.lib } }, plugins: [ + ...(user_config.plugins || []), svelte({ extensions: config.extensions }) @@ -457,16 +473,22 @@ async function build_service_worker( .trim() ); + /** @type {any} */ + const user_config = config.kit.vite(); + await vite.build({ + ...user_config, root: cwd, base, build: { + ...user_config.build, lib: { entry: service_worker_entry_file, name: 'app', formats: ['es'] }, rollupOptions: { + ...(user_config.build && user_config.build.rollupOptions), output: { entryFileNames: 'service-worker.js' } @@ -475,7 +497,9 @@ async function build_service_worker( emptyOutDir: false }, resolve: { + ...user_config.resolve, alias: { + ...(user_config.resolve && user_config.resolve.alias), '$service-worker': path.resolve(`${build_dir}/runtime/service-worker`) } }, diff --git a/packages/kit/src/core/dev/index.js b/packages/kit/src/core/dev/index.js index 5a4381cf7632..e9323a43c919 100644 --- a/packages/kit/src/core/dev/index.js +++ b/packages/kit/src/core/dev/index.js @@ -73,24 +73,33 @@ class Watcher extends EventEmitter { } async init_server() { + /** @type {any} */ + const user_config = (this.config.kit.vite && this.config.kit.vite()) || {}; + /** * @type {vite.ViteDevServer} */ this.viteDevServer = await vite.createServer({ + ...user_config, + configFile: false, root: this.cwd, resolve: { + ...user_config.resolve, alias: { + ...(user_config.resolve && user_config.resolve.alias), $app: path.resolve(`${this.dir}/runtime/app`), $lib: this.config.kit.files.lib } }, plugins: [ + ...(user_config.plugins || []), svelte({ extensions: this.config.extensions }) ], publicDir: this.config.kit.files.assets, server: { + ...user_config.server, middlewareMode: true } }); diff --git a/packages/kit/src/core/load_config/index.spec.js b/packages/kit/src/core/load_config/index.spec.js index 82e5b870e274..67ff9b8d8f1a 100644 --- a/packages/kit/src/core/load_config/index.spec.js +++ b/packages/kit/src/core/load_config/index.spec.js @@ -5,6 +5,8 @@ import { validate_config } from './index.js'; test('fills in defaults', () => { const validated = validate_config({}); + delete validated.kit.vite; + assert.equal(validated, { compilerOptions: null, extensions: ['.svelte'], @@ -77,6 +79,10 @@ test('fills in partial blanks', () => { } }); + assert.equal(validated.kit.vite(), {}); + + delete validated.kit.vite; + assert.equal(validated, { compilerOptions: null, extensions: ['.svelte'], diff --git a/packages/kit/src/core/load_config/options.js b/packages/kit/src/core/load_config/options.js index 4eb5538087e5..0b42c25c420c 100644 --- a/packages/kit/src/core/load_config/options.js +++ b/packages/kit/src/core/load_config/options.js @@ -107,7 +107,26 @@ const options = { } }, - target: expect_string(null) + target: expect_string(null), + + vite: { + type: 'leaf', + default: () => ({}), + validate: (option, keypath) => { + if (typeof option === 'object') { + const config = option; + option = () => config; + } + + if (typeof option !== 'function') { + throw new Error( + `${keypath} must be a Vite config object (https://vitejs.dev/config) or a function that returns one` + ); + } + + return option; + } + } } }, diff --git a/packages/kit/src/core/load_config/test/index.js b/packages/kit/src/core/load_config/test/index.js index 93463b9a22ae..15e64d398f91 100644 --- a/packages/kit/src/core/load_config/test/index.js +++ b/packages/kit/src/core/load_config/test/index.js @@ -14,6 +14,8 @@ suite('load default config', async () => { const config = await load_config({ cwd }); + delete config.kit.vite; // can't test equality of a function + assert.equal(config, { compilerOptions: null, extensions: ['.svelte'], diff --git a/packages/kit/test/apps/basics/svelte.config.cjs b/packages/kit/test/apps/basics/svelte.config.cjs index 2ae505a43df8..2a32abf6e191 100644 --- a/packages/kit/test/apps/basics/svelte.config.cjs +++ b/packages/kit/test/apps/basics/svelte.config.cjs @@ -1,8 +1,12 @@ module.exports = { kit: { - // TODO adapterless builds adapter: '@sveltejs/adapter-node', - - hostHeader: 'x-forwarded-host' + hostHeader: 'x-forwarded-host', + vite: { + build: { + minify: false + }, + clearScreen: false + } } }; diff --git a/packages/kit/test/apps/basics/vite.config.js b/packages/kit/test/apps/basics/vite.config.js deleted file mode 100644 index 6c565e6d3016..000000000000 --- a/packages/kit/test/apps/basics/vite.config.js +++ /dev/null @@ -1,6 +0,0 @@ -export default { - build: { - minify: false - }, - clearScreen: false -}; diff --git a/packages/kit/test/apps/custom-extension/vite.config.js b/packages/kit/test/apps/custom-extension/vite.config.js deleted file mode 100644 index 4f4dfee7f1e4..000000000000 --- a/packages/kit/test/apps/custom-extension/vite.config.js +++ /dev/null @@ -1,5 +0,0 @@ -import { resolve } from 'path'; - -export default { - resolve: {} -}; diff --git a/packages/kit/test/apps/options/svelte.config.cjs b/packages/kit/test/apps/options/svelte.config.cjs index a8d5707c92de..1f6d70bb1070 100644 --- a/packages/kit/test/apps/options/svelte.config.cjs +++ b/packages/kit/test/apps/options/svelte.config.cjs @@ -1,19 +1,20 @@ module.exports = { kit: { - // TODO adapterless builds adapter: '@sveltejs/adapter-node', - files: { assets: 'public', lib: 'source/components', routes: 'source/pages', template: 'source/template.html' }, - appDir: '_wheee', - target: '#content-goes-here', - - host: 'example.com' + host: 'example.com', + vite: { + build: { + minify: false + }, + clearScreen: false + } } }; diff --git a/packages/kit/test/apps/options/vite.config.js b/packages/kit/test/apps/options/vite.config.js deleted file mode 100644 index 6c565e6d3016..000000000000 --- a/packages/kit/test/apps/options/vite.config.js +++ /dev/null @@ -1,6 +0,0 @@ -export default { - build: { - minify: false - }, - clearScreen: false -}; diff --git a/packages/kit/types.internal.d.ts b/packages/kit/types.internal.d.ts index b80f94d6060e..29a71accc963 100644 --- a/packages/kit/types.internal.d.ts +++ b/packages/kit/types.internal.d.ts @@ -43,6 +43,7 @@ export type ValidatedConfig = { pages: string[]; }; target: string; + vite: () => {}; }; preprocess: any; }; From 9385d98563c9e06448e76e3e7e54c3efa745c940 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 18 Mar 2021 17:32:03 -0400 Subject: [PATCH 2/7] changeset --- .changeset/swift-pumpkins-pump.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/swift-pumpkins-pump.md diff --git a/.changeset/swift-pumpkins-pump.md b/.changeset/swift-pumpkins-pump.md new file mode 100644 index 000000000000..b9e4baabcb1b --- /dev/null +++ b/.changeset/swift-pumpkins-pump.md @@ -0,0 +1,6 @@ +--- +'create-svelte': patch +'@sveltejs/kit': patch +--- + +Move Vite config into svelte.config.cjs From c051a2b320cb0d5634c601d675784c5901679c61 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 18 Mar 2021 17:34:57 -0400 Subject: [PATCH 3/7] message for people with a vite.config.js --- packages/kit/src/cli.js | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/packages/kit/src/cli.js b/packages/kit/src/cli.js index 2a3ba035163d..4b2974b1bfec 100644 --- a/packages/kit/src/cli.js +++ b/packages/kit/src/cli.js @@ -8,26 +8,13 @@ async function get_config() { if (existsSync('snowpack.config.js') || existsSync('snowpack.config.cjs')) { // prettier-ignore console.error(colors.bold().red( - 'SvelteKit now uses https://vitejs.dev. Please replace snowpack.config.js with vite.config.js:' + 'SvelteKit now uses https://vitejs.dev. Please remove snowpack.config.js and put Vite config in svelte.config.cjs: https://kit.svelte.dev/docs#configuration-vite' )); - + } else if (existsSync('vite.config.js')) { // prettier-ignore - console.error(` - // Consult https://vitejs.dev/config/ to learn about these options - import { join } 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 { - ssr: { - noExternal: Object.keys(pkg.dependencies || {}) - } - }; - - `.replace(/^\t{3}/gm, '').replace(/\t/gm, ' ').trim()); + console.error(colors.bold().red( + 'Please remove vite.config.js and put Vite config in svelte.config.cjs: https://kit.svelte.dev/docs#configuration-vite' + )); } try { @@ -38,8 +25,7 @@ async function get_config() { if (error.code === 'MODULE_NOT_FOUND') { if (existsSync('svelte.config.js')) { // TODO this is temporary, for the benefit of early adopters - message = - 'You must rename svelte.config.js to svelte.config.cjs, and snowpack.config.js to snowpack.config.cjs'; + message = 'You must rename svelte.config.js to svelte.config.cjs'; } else { message = 'Missing svelte.config.cjs'; } From 40a493f0a1a3440ca307b9d47484d4c74002dde9 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 18 Mar 2021 17:35:25 -0400 Subject: [PATCH 4/7] add configFile: false --- packages/kit/src/core/build/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/kit/src/core/build/index.js b/packages/kit/src/core/build/index.js index 4fcdac1c5d73..fa9cc8545430 100644 --- a/packages/kit/src/core/build/index.js +++ b/packages/kit/src/core/build/index.js @@ -114,6 +114,7 @@ async function build_client({ await vite.build({ ...user_config, + configFile: false, root: cwd, base, build: { @@ -383,6 +384,7 @@ async function build_server( await vite.build({ ...user_config, + configFile: false, root: cwd, base, build: { @@ -478,6 +480,7 @@ async function build_service_worker( await vite.build({ ...user_config, + configFile: false, root: cwd, base, build: { From 3055a1fe765ffc19b9568bf44bbf48f93985e63c Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 18 Mar 2021 17:39:48 -0400 Subject: [PATCH 5/7] add docs for config.kit.vite --- documentation/docs/13-configuration.md | 33 +++++++++++++++----------- packages/kit/src/core/build/index.js | 4 ++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/documentation/docs/13-configuration.md b/documentation/docs/13-configuration.md index baaf02b13099..507b4de82fe8 100644 --- a/documentation/docs/13-configuration.md +++ b/documentation/docs/13-configuration.md @@ -37,7 +37,8 @@ module.exports = { force: false, pages: ['*'] }, - target: null + target: null, + vite: () => ({}) }, // options passed to svelte.preprocess (https://svelte.dev/docs#svelte_preprocess) @@ -61,12 +62,12 @@ The directory relative to `paths.assets` where the built JS and CSS (and importe An object containing zero or more of the following `string` values: -* `assets` — a place to put static files that should have stable URLs and undergo no processing, such as `favicon.ico` or `manifest.json` -* `lib` — your app's internal library, accessible throughout the codebase as `$lib` -* `routes` — the files that define the structure of your app (see [Routing](#routing)) -* `serviceWorker` — the location of your service worker's entry point (see [Service workers](#service-workers)) -* `setup` — the location of your setup file (see [Setup](#setup)) -* `template` — the location of the template for HTML responses +- `assets` — a place to put static files that should have stable URLs and undergo no processing, such as `favicon.ico` or `manifest.json` +- `lib` — your app's internal library, accessible throughout the codebase as `$lib` +- `routes` — the files that define the structure of your app (see [Routing](#routing)) +- `serviceWorker` — the location of your service worker's entry point (see [Service workers](#service-workers)) +- `setup` — the location of your setup file (see [Setup](#setup)) +- `template` — the location of the template for HTML responses #### host @@ -91,18 +92,22 @@ module.exports = { An object containing zero or more of the following `string` values: -* `assets` — an absolute path, or a path relative to `base`, where your app's files are served from. This is useful if your files are served from a storage bucket of some kind -* `base` — a root-relative (i.e. starts with `/`) path that specifies where your app is served from. This allows the app to live on a non-root path +- `assets` — an absolute path, or a path relative to `base`, where your app's files are served from. This is useful if your files are served from a storage bucket of some kind +- `base` — a root-relative (i.e. starts with `/`) path that specifies where your app is served from. This allows the app to live on a non-root path #### prerender See [Prerendering](#prerendering). An object containing zero or more of the following: -* `crawl` — determines whether SvelteKit should find pages to prerender by following links from the seed page(s) -* `enabled` — set to `false` to disable prerendering altogether -* `force` — if `true`, a page that fails to render will _not_ cause the entire build to fail -* `pages` — an array of pages to prerender, or start crawling from (if `crawl: true`). The `*` string includes all non-dynamic routes (i.e. pages with no `[parameters]` ) +- `crawl` — determines whether SvelteKit should find pages to prerender by following links from the seed page(s) +- `enabled` — set to `false` to disable prerendering altogether +- `force` — if `true`, a page that fails to render will _not_ cause the entire build to fail +- `pages` — an array of pages to prerender, or start crawling from (if `crawl: true`). The `*` string includes all non-dynamic routes (i.e. pages with no `[parameters]` ) #### target -Specifies an element to mount the app to. It must be a DOM selector that identifies an element that exists in your template file. If unspecified, the app will be mounted to `document.body`. \ No newline at end of file +Specifies an element to mount the app to. It must be a DOM selector that identifies an element that exists in your template file. If unspecified, the app will be mounted to `document.body`. + +#### vite + +A [Vite config object](https://vitejs.dev/config), or a function that returns one. Not all configuration options can be set, since SvelteKit depends on certain values being configured internally. diff --git a/packages/kit/src/core/build/index.js b/packages/kit/src/core/build/index.js index fa9cc8545430..edf30f8e1392 100644 --- a/packages/kit/src/core/build/index.js +++ b/packages/kit/src/core/build/index.js @@ -388,6 +388,7 @@ async function build_server( root: cwd, base, build: { + target: 'es2018', ...user_config.build, ssr: true, lib: { @@ -395,8 +396,7 @@ async function build_server( name: 'app', formats: ['es'] }, - outDir: `${output_dir}/server`, - target: 'es2018' + outDir: `${output_dir}/server` }, resolve: { ...user_config.resolve, From 414bb998b581ff3aed7b543de6e5c3364ba45081 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 18 Mar 2021 17:43:48 -0400 Subject: [PATCH 6/7] fix ssr config --- packages/kit/src/core/build/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/kit/src/core/build/index.js b/packages/kit/src/core/build/index.js index edf30f8e1392..f39de1d3e96c 100644 --- a/packages/kit/src/core/build/index.js +++ b/packages/kit/src/core/build/index.js @@ -417,7 +417,12 @@ async function build_server( // so we need to ignore the fact that it's missing // @ts-ignore ssr: { - noExternal: ['svelte', '@sveltejs/kit'] + ...user_config.ssr, + noExternal: [ + 'svelte', + '@sveltejs/kit', + ...((user_config.ssr && user_config.ssr.noExternal) || []) + ] }, optimizeDeps: { entries: [] From f8f7e707b92b1863507f2c65ccd700009da65bbf Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 18 Mar 2021 18:14:35 -0400 Subject: [PATCH 7/7] update user-facing config type --- packages/kit/types.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/kit/types.d.ts b/packages/kit/types.d.ts index a462be3444db..d188c896f81c 100644 --- a/packages/kit/types.d.ts +++ b/packages/kit/types.d.ts @@ -28,6 +28,7 @@ export type Config = { pages?: string[]; }; target?: string; + vite?: {} | (() => {}); }; preprocess?: any; };