Skip to content

Commit 1126f9b

Browse files
committed
[breaking] do a single bundling with Vite removing esbuild
1 parent 52c0f99 commit 1126f9b

File tree

32 files changed

+133
-392
lines changed

32 files changed

+133
-392
lines changed

.changeset/tidy-pets-tan.md

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

documentation/docs/80-adapter-api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default function (options) {
1414
/** @type {import('@sveltejs/kit').Adapter} */
1515
return {
1616
name: 'adapter-package-name',
17+
serverEntryPoint: 'adapter-package-name/entry',
1718
async adapt({ utils, config }) {
1819
// adapter implementation
1920
}
Lines changed: 2 additions & 2 deletions
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/README.md

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -64,37 +64,6 @@ npm run build && wrangler publish
6464

6565
More info on configuring a cloudflare worker site can be found [here](https://developers.cloudflare.com/workers/platform/sites/start-from-existing)
6666

67-
## Advanced Configuration
68-
69-
### esbuild
70-
71-
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.
72-
73-
For example, you may wish to add a plugin:
74-
75-
```js
76-
adapterCfw({
77-
esbuild(options) {
78-
return {
79-
...options,
80-
plugins: []
81-
};
82-
}
83-
});
84-
```
85-
86-
The default options for this version are as follows:
87-
88-
```js
89-
const options = {
90-
entryPoints: ['.svelte-kit/cloudflare-workers/entry.js'],
91-
outfile: `${entrypoint}/index.js`,
92-
bundle: true,
93-
target: 'es2020',
94-
platform: 'browser'
95-
};
96-
```
97-
9867
## Changelog
9968

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

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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
import fs from 'fs';
22
import { execSync } from 'child_process';
3-
import esbuild from 'esbuild';
43
import toml from '@iarna/toml';
54
import { fileURLToPath } from 'url';
65

7-
/**
8-
* @typedef {import('esbuild').BuildOptions} BuildOptions
9-
*/
10-
116
/** @type {import('.')} */
12-
export default function (options) {
7+
export default function () {
138
return {
149
name: '@sveltejs/adapter-cloudflare-workers',
1510

@@ -34,20 +29,6 @@ export default function (options) {
3429
utils.log.minor('Generating worker...');
3530
utils.copy(`${files}/entry.js`, '.svelte-kit/cloudflare-workers/entry.js');
3631

37-
/** @type {BuildOptions} */
38-
const default_options = {
39-
entryPoints: ['.svelte-kit/cloudflare-workers/entry.js'],
40-
outfile: `${entrypoint}/index.js`,
41-
bundle: true,
42-
target: 'es2020',
43-
platform: 'browser'
44-
};
45-
46-
const build_options =
47-
options && options.esbuild ? await options.esbuild(default_options) : default_options;
48-
49-
await esbuild.build(build_options);
50-
5132
fs.writeFileSync(`${entrypoint}/package.json`, JSON.stringify({ main: 'index.js' }));
5233

5334
utils.log.info('Prerendering static pages...');

packages/adapter-cloudflare-workers/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore"
2727
},
2828
"dependencies": {
29-
"@iarna/toml": "^2.2.5",
30-
"esbuild": "^0.13.4"
29+
"@iarna/toml": "^2.2.5"
3130
},
3231
"devDependencies": {
3332
"@sveltejs/kit": "workspace:*"

packages/adapter-netlify/README.md

Lines changed: 0 additions & 32 deletions
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/adapter-netlify/index.js

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import { appendFileSync, existsSync, readFileSync, writeFileSync } from 'fs';
22
import { join, resolve } from 'path';
33
import { fileURLToPath } from 'url';
4-
import esbuild from 'esbuild';
54
import toml from '@iarna/toml';
65

7-
/**
8-
* @typedef {import('esbuild').BuildOptions} BuildOptions
9-
*/
10-
116
/** @type {import('.')} */
12-
export default function (options) {
7+
export default function () {
138
return {
149
name: '@sveltejs/adapter-netlify',
10+
serverEntryPoint: '@sveltejs/adapter-netlify/entry',
1511

1612
async adapt({ utils }) {
1713
// "build" is the default publish directory when Netlify detects SvelteKit
@@ -24,24 +20,7 @@ export default function (options) {
2420
const files = fileURLToPath(new URL('./files', import.meta.url));
2521

2622
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-
23+
utils.copy(files, '.netlify');
4524
writeFileSync(join('.netlify', 'package.json'), JSON.stringify({ type: 'commonjs' }));
4625

4726
utils.log.minor('Prerendering static pages...');

packages/adapter-netlify/package.json

Lines changed: 4 additions & 2 deletions
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

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +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
24+
## Build Options
2925

3026
### entryPoint
3127

@@ -39,15 +35,17 @@ The directory to build the server to. It defaults to `build` — i.e. `node buil
3935

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

42-
### env
38+
## Runtime Options
39+
40+
### Environment variables
4341

4442
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:
4543

4644
```
4745
HOST=127.0.0.1 PORT=4000 node build
4846
```
4947

50-
You can specify different environment variables if necessary using the `env` option.
48+
You can also specify `SOCKET_PATH` if you'd like to use a Unix domain socket or Windows named pipe.
5149

5250
## Middleware
5351

@@ -83,43 +81,6 @@ app.listen(3000);
8381

8482
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).
8583

86-
## Advanced Configuration
87-
88-
### esbuild
89-
90-
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.
91-
92-
For example, you may wish to add a plugin:
93-
94-
```js
95-
adapterNode({
96-
esbuild(defaultOptions) {
97-
return {
98-
...defaultOptions,
99-
plugins: []
100-
};
101-
}
102-
});
103-
```
104-
105-
The default options for this version are as follows:
106-
107-
```js
108-
{
109-
entryPoints: ['.svelte-kit/node/index.js'],
110-
outfile: 'pathTo/index.js',
111-
bundle: true,
112-
external: allProductionDependencies, // from package.json
113-
format: 'esm',
114-
platform: 'node',
115-
target: 'node14',
116-
inject: ['pathTo/shims.js'],
117-
define: {
118-
esbuild_app_dir: `"${config.kit.appDir}"`
119-
}
120-
}
121-
```
122-
12384
## Changelog
12485

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

0 commit comments

Comments
 (0)