Skip to content

Commit 65012e0

Browse files
committed
[breaking] do a single bundling with Vite removing esbuild
1 parent c75dcde commit 65012e0

File tree

36 files changed

+156
-316
lines changed

36 files changed

+156
-316
lines changed

.changeset/tidy-pets-tan.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@sveltejs/adapter-cloudflare': patch
3+
'@sveltejs/adapter-cloudflare-workers': patch
4+
'@sveltejs/adapter-netlify': patch
5+
'@sveltejs/adapter-node': patch
6+
'@sveltejs/adapter-vercel': patch
7+
'@sveltejs/kit': patch
8+
---
9+
10+
[breaking] do a single bundling with Vite making esbuild optional

documentation/docs/10-adapters.md

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export default function (options) {
7474
/** @type {import('@sveltejs/kit').Adapter} */
7575
return {
7676
name: 'adapter-package-name',
77+
serverEntryPoint: 'adapter-package-name/entry',
7778
async adapt({ utils, config }) {
7879
// adapter implementation
7980
}

documentation/docs/14-configuration.md

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const config = {
4747
onError: 'fail'
4848
},
4949
router: true,
50+
serverEntryPoint: null,
5051
serviceWorker: {
5152
files: (filepath) => !/\.DS_STORE/.test(filepath)
5253
},
@@ -195,6 +196,10 @@ See [Prerendering](#ssr-and-javascript-prerender). An object containing zero or
195196

196197
Enables or disables the client-side [router](#ssr-and-javascript-router) app-wide.
197198

199+
### serverEntryPoint
200+
201+
A file path to a custom entry point for the server. Passed to `vite.build.rollupOptions.input`. See [the Rollup docs](https://rollupjs.org/guide/en/#input) for more info.
202+
198203
### serviceWorker
199204

200205
An object containing zero or more of the following values:
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import netlify from '@sveltejs/adapter-netlify';
1+
import adapter from '@sveltejs/adapter-netlify';
22

33
export default {
44
kit: {
5-
adapter: netlify(),
5+
adapter: adapter(),
66
target: '#svelte'
77
}
88
};

packages/adapter-cloudflare-workers/files/entry.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// TODO hardcoding the relative location makes this brittle
2-
import { init, render } from '../output/server/app.js';
1+
// $server-build doesn't exist until the app is built
2+
// @ts-expect-error
3+
import { init, render } from '$server-build';
34
import { getAssetFromKV, NotFoundError } from '@cloudflare/kv-asset-handler';
45

56
init();

packages/adapter-cloudflare-workers/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { fileURLToPath } from 'url';
1212
export default function (options) {
1313
return {
1414
name: '@sveltejs/adapter-cloudflare-workers',
15+
serverEntryPoint: '@sveltejs/adapter-cloudflare-workers/entry',
1516

1617
async adapt({ utils }) {
1718
const { site } = validate_config(utils);

packages/adapter-cloudflare-workers/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
".": {
1313
"import": "./index.js"
1414
},
15+
"./entry": {
16+
"import": "./files/entry.js"
17+
},
1518
"./package.json": "./package.json"
1619
},
1720
"main": "index.js",

packages/adapter-cloudflare/files/worker.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* global ASSETS */
2-
import { init, render } from '../output/server/app.js';
2+
// $server-build doesn't exist until the app is built
3+
// @ts-expect-error
4+
import { init, render } from '$server-build';
35

46
init();
57

packages/adapter-cloudflare/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as esbuild from 'esbuild';
99
export default function (options = {}) {
1010
return {
1111
name: '@sveltejs/adapter-cloudflare',
12+
serverEntryPoint: '@sveltejs/adapter-cloudflare/entry',
1213
async adapt({ utils, config }) {
1314
const files = fileURLToPath(new URL('./files', import.meta.url));
1415
const target_dir = join(process.cwd(), '.svelte-kit', 'cloudflare');

packages/adapter-cloudflare/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
".": {
1313
"import": "./index.js"
1414
},
15+
"./entry": {
16+
"import": "./files/worker.js"
17+
},
1518
"./package.json": "./package.json"
1619
},
1720
"types": "index.d.ts",

packages/adapter-netlify/README.md

-32
Original file line numberDiff line numberDiff line change
@@ -66,38 +66,6 @@ During compilation a required "catch all" redirect rule is automatically appende
6666
node_bundler = "esbuild"
6767
```
6868

69-
## Advanced Configuration
70-
71-
### esbuild
72-
73-
As an escape hatch, you may optionally specify a function which will receive the final esbuild options generated by this adapter and returns a modified esbuild configuration. The result of this function will be passed as-is to esbuild. The function can be async.
74-
75-
For example, you may wish to add a plugin:
76-
77-
```js
78-
adapterNetlify({
79-
esbuild(defaultOptions) {
80-
return {
81-
...defaultOptions,
82-
plugins: []
83-
};
84-
}
85-
});
86-
```
87-
88-
The default options for this version are as follows:
89-
90-
```js
91-
{
92-
entryPoints: ['.svelte-kit/netlify/entry.js'],
93-
// This is Netlify's internal functions directory, not the one for user functions.
94-
outfile: '.netlify/functions-internal/__render.js',
95-
bundle: true,
96-
inject: ['pathTo/shims.js'],
97-
platform: 'node'
98-
}
99-
```
100-
10169
## Changelog
10270

10371
[The Changelog for this package is available on GitHub](https://github.com./sveltejs/kit/blob/master/packages/adapter-netlify/CHANGELOG.md).

packages/adapter-netlify/files/entry.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// TODO hardcoding the relative location makes this brittle
2-
import { init, render } from '../output/server/app.js';
1+
import '@sveltejs/kit/install-fetch';
2+
// $server-build doesn't exist until the app is built
3+
// @ts-expect-error
4+
import { init, render } from '$server-build';
35

46
init();
57

packages/adapter-netlify/files/shims.js

-1
This file was deleted.

packages/adapter-netlify/index.js

+5-29
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
import { appendFileSync, existsSync, readFileSync, writeFileSync } from 'fs';
1+
import { appendFileSync, existsSync, readFileSync } from 'fs';
22
import { join, resolve } from 'path';
3-
import { fileURLToPath } from 'url';
4-
import esbuild from 'esbuild';
53
import toml from '@iarna/toml';
64

7-
/**
8-
* @typedef {import('esbuild').BuildOptions} BuildOptions
9-
*/
10-
115
/** @type {import('.')} */
12-
export default function (options) {
6+
export default function () {
137
return {
148
name: '@sveltejs/adapter-netlify',
9+
serverEntryPoint: '@sveltejs/adapter-netlify/entry',
1510

1611
async adapt({ utils }) {
1712
// "build" is the default publish directory when Netlify detects SvelteKit
@@ -21,28 +16,9 @@ export default function (options) {
2116

2217
utils.rimraf(publish);
2318

24-
const files = fileURLToPath(new URL('./files', import.meta.url));
25-
2619
utils.log.minor('Generating serverless function...');
27-
utils.copy(join(files, 'entry.js'), '.svelte-kit/netlify/entry.js');
28-
29-
/** @type {BuildOptions} */
30-
const default_options = {
31-
entryPoints: ['.svelte-kit/netlify/entry.js'],
32-
// Any functions in ".netlify/functions-internal" are bundled in addition to user-defined Netlify functions.
33-
// See https://github.com./netlify/build/pull/3213 for more details
34-
outfile: '.netlify/functions-internal/__render.js',
35-
bundle: true,
36-
inject: [join(files, 'shims.js')],
37-
platform: 'node'
38-
};
39-
40-
const build_options =
41-
options && options.esbuild ? await options.esbuild(default_options) : default_options;
42-
43-
await esbuild.build(build_options);
44-
45-
writeFileSync(join('.netlify', 'package.json'), JSON.stringify({ type: 'commonjs' }));
20+
utils.copy('.svelte-kit/output/server/index.js', '.netlify/functions-internal/__render.js');
21+
utils.copy('.svelte-kit/output/server/chunks', '.netlify/functions-internal/chunks');
4622

4723
utils.log.minor('Prerendering static pages...');
4824
await utils.prerender({

packages/adapter-netlify/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
".": {
1313
"import": "./index.js"
1414
},
15+
"./entry": {
16+
"import": "./files/entry.js"
17+
},
1518
"./package.json": "./package.json"
1619
},
1720
"main": "index.js",
@@ -26,8 +29,7 @@
2629
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore"
2730
},
2831
"dependencies": {
29-
"@iarna/toml": "^2.2.5",
30-
"esbuild": "^0.13.4"
32+
"@iarna/toml": "^2.2.5"
3133
},
3234
"devDependencies": {
3335
"@sveltejs/kit": "workspace:*"

packages/adapter-node/README.md

+7-61
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,13 @@ export default {
1515
adapter: adapter({
1616
// default options are shown
1717
out: 'build',
18-
precompress: false,
19-
env: {
20-
host: 'HOST',
21-
port: 'PORT'
22-
}
18+
precompress: false
2319
})
2420
}
2521
};
2622
```
2723

28-
## Options
29-
30-
### entryPoint
31-
32-
The server entry point. Allows you to provide a [custom server implementation](#middleware). Defaults to the provided reference server.
24+
## Build Options
3325

3426
### out
3527

@@ -39,32 +31,23 @@ The directory to build the server to. It defaults to `build` — i.e. `node buil
3931

4032
Enables precompressing using gzip and brotli for assets and prerendered pages. It defaults to `false`.
4133

42-
### env
34+
## Runtime Options
35+
36+
### Environment variables
4337

4438
By default, the server will accept connections on `0.0.0.0` using port 3000. These can be customised with the `PORT` and `HOST` environment variables:
4539

4640
```
4741
HOST=127.0.0.1 PORT=4000 node build
4842
```
4943

50-
You can specify different environment variables if necessary using the `env` option:
51-
52-
```js
53-
env: {
54-
host: 'MY_HOST_VARIABLE',
55-
port: 'MY_PORT_VARIABLE'
56-
}
57-
```
58-
59-
```
60-
MY_HOST_VARIABLE=127.0.0.1 MY_PORT_VARIABLE=4000 node build
61-
```
44+
You can also specify `SOCKET_PATH` if you'd like to use a Unix domain socket or Windows named pipe.
6245

6346
## Middleware
6447

6548
The adapter exports a middleware `(req, res, next) => {}` that's compatible with [Express](https://github.com./expressjs/expressjs.com) / [Connect](https://github.com./senchalabs/connect) / [Polka](https://github.com./lukeed/polka). Additionally, it also exports a reference server implementation using this middleware with a plain Node HTTP server.
6649

67-
But you can use your favorite server framework to combine it with other middleware and server logic. You can import `kitMiddleware`, your ready-to-use SvelteKit middleware from the `build` directory. You can use [the `entryPoint` option](#entryPoint) to bundle your custom server entry point.
50+
But you can use your favorite server framework to combine it with other middleware and server logic. You can import `kitMiddleware`, your ready-to-use SvelteKit middleware from the `build` directory. You can use [the `serverEntryPoint` option](https://kit.svelte.dev/docs#configuration-serverentrypoint) to bundle your custom server entry point.
6851

6952
```js
7053
// src/server.js
@@ -94,43 +77,6 @@ app.listen(3000);
9477

9578
For using middleware in dev mode, [see the FAQ](https://kit.svelte.dev/faq#how-do-i-use-x-with-sveltekit-how-do-i-use-middleware).
9679

97-
## Advanced Configuration
98-
99-
### esbuild
100-
101-
As an escape hatch, you may optionally specify a function which will receive the final esbuild options generated by this adapter and returns a modified esbuild configuration. The result of this function will be passed as-is to esbuild. The function can be async.
102-
103-
For example, you may wish to add a plugin:
104-
105-
```js
106-
adapterNode({
107-
esbuild(defaultOptions) {
108-
return {
109-
...defaultOptions,
110-
plugins: []
111-
};
112-
}
113-
});
114-
```
115-
116-
The default options for this version are as follows:
117-
118-
```js
119-
{
120-
entryPoints: ['.svelte-kit/node/index.js'],
121-
outfile: 'pathTo/index.js',
122-
bundle: true,
123-
external: allProductionDependencies, // from package.json
124-
format: 'esm',
125-
platform: 'node',
126-
target: 'node14',
127-
inject: ['pathTo/shims.js'],
128-
define: {
129-
esbuild_app_dir: `"${config.kit.appDir}"`
130-
}
131-
}
132-
```
133-
13480
## Deploying
13581

13682
You will need the output directory (`build` by default), the project's `package.json`, and the production dependencies in `node_modules` to run the application. Production dependencies can be generated with `npm ci --prod`, you can also skip this step if your app doesn't have any dependencies. You can then start your app with

0 commit comments

Comments
 (0)