Skip to content

Commit

Permalink
bundle with rollup instead of esbuild (#6896)
Browse files Browse the repository at this point in the history
* bundle with rollup instead of esbuild

* remove esbuild

* oops

* add comment

* fix package.json
  • Loading branch information
Rich-Harris committed Sep 20, 2022
1 parent 5a54eb4 commit bd1a3ef
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 46 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-beds-smile.md
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-node': patch
---

Bundle with rollup instead of esbuild
30 changes: 20 additions & 10 deletions packages/adapter-node/index.js
@@ -1,6 +1,9 @@
import { readFileSync, writeFileSync } from 'fs';
import { fileURLToPath } from 'url';
import * as esbuild from 'esbuild';
import { rollup } from 'rollup';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';

const files = fileURLToPath(new URL('./files', import.meta.url).href);

Expand Down Expand Up @@ -49,16 +52,23 @@ export default function (opts = {}) {

const pkg = JSON.parse(readFileSync('package.json', 'utf8'));

await esbuild.build({
platform: 'node',
sourcemap: 'linked',
target: 'es2022',
entryPoints: [`${tmp}/index.js`, `${tmp}/manifest.js`],
outdir: `${out}/server`,
splitting: true,
// we bundle the Vite output so that deployments only need
// their production dependencies. Anything in devDependencies
// will get included in the bundled code
const bundle = await rollup({
input: {
index: `${tmp}/index.js`,
manifest: `${tmp}/manifest.js`
},
external: [...Object.keys(pkg.dependencies || {})],
plugins: [nodeResolve(), commonjs(), json()]
});

await bundle.write({
dir: `${out}/server`,
format: 'esm',
bundle: true,
external: [...Object.keys(pkg.dependencies || {})]
sourcemap: true,
chunkFileNames: `chunks/[name]-[hash].js`
});

builder.copy(files, out, {
Expand Down
5 changes: 3 additions & 2 deletions packages/adapter-node/package.json
Expand Up @@ -32,7 +32,6 @@
"prepublishOnly": "npm run build"
},
"devDependencies": {
"@rollup/plugin-json": "^4.1.0",
"@sveltejs/kit": "workspace:*",
"@types/node": "^16.11.36",
"c8": "^7.11.3",
Expand All @@ -45,6 +44,8 @@
"uvu": "^0.5.3"
},
"dependencies": {
"esbuild": "^0.15.7"
"@rollup/plugin-commonjs": "^22.0.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^14.1.0"
}
}
40 changes: 6 additions & 34 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bd1a3ef

Please sign in to comment.