Skip to content

Commit

Permalink
[breaking] graduate @sveltejs/kit/vite from experimental and requir…
Browse files Browse the repository at this point in the history
…e `vite.config.js` (#5332)

* [breaking] graduate @sveltejs/kit/vite from experimental

* update site and tests to use vite.config.js

* Add vite.config.js to the create-svelte templates

* [breaking] require vite.config.js

* turbo can go to hell

* wtf pnpm

* revert b6b9208

* fix some turbo config

* lint

* check

* Update packages/kit/src/cli.js

Co-authored-by: Rich Harris <richard.a.harris@gmail.com>

* [breaking] switch to vite CLI for dev, build, and preview commands

* Clarify message

* more updates to test projects

* remove svelte-kit dev/build/preview commands

* a few more fixes

* lint

* fix adapter-static tests

* docs

* update lockfile, not sure how it got borked

* lockfile

* doc typos

* bump undici

* bump @rollup/plugin-commonjs

* fix config validation

* fix #5308

* adapter-static tests

* update svelte-kit sync docs

* update svelte-kit package docs

* Revert "adapter-static tests"

This reverts commit aa76235.

* fix workspace/prepare scripts

* Revert "fix workspace/prepare scripts"

This reverts commit 9ece16a.

* Revert "Revert "adapter-static tests""

This reverts commit 72432bb.

* try something else

* remove debug line

* try using edge functions

* Revert "try using edge functions"

This reverts commit 5b2eebd.

* remove unused file

* update gitignore so we can run vc build locally to diagnose hanging

* tweak CLI docs

* trying this once more

* doh

* use workspace dependencies

* ugh lockfile

* use src code locally, dist in CI

Co-authored-by: Rich Harris <hello@rich-harris.dev>
Co-authored-by: Rich Harris <richard.a.harris@gmail.com>
  • Loading branch information
3 people authored Jul 5, 2022
1 parent 61d3d29 commit 2e2719c
Show file tree
Hide file tree
Showing 75 changed files with 1,190 additions and 1,277 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-trainers-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[breaking] require vite.config.js
5 changes: 5 additions & 0 deletions .changeset/light-kings-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-svelte': patch
---

Add vite.config.js to the create-svelte templates
5 changes: 5 additions & 0 deletions .changeset/proud-phones-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/kit": patch
---

[breaking] graduate @sveltejs/kit/vite from experimental
6 changes: 6 additions & 0 deletions .changeset/unlucky-oranges-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'create-svelte': patch
'@sveltejs/kit': patch
---

[breaking] switch to vite CLI for dev, build, and preview commands
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ yarn.lock
.cloudflare
.pnpm-debug.log
.netlify
.turbo
.turbo
.vercel
2 changes: 1 addition & 1 deletion documentation/docs/07-service-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ In SvelteKit, if you have a `src/service-worker.js` file (or `src/service-worker
Inside the service worker you have access to the [`$service-worker` module](/docs/modules#$service-worker).

Because it needs to be bundled (since browsers don't yet support `import` in this context), and depends on the client-side app's build manifest, **service workers only work in the production build, not in development**. To test it locally, use [`svelte-kit preview`](/docs/cli#svelte-kit-preview).
Because it needs to be bundled (since browsers don't yet support `import` in this context), and depends on the client-side app's build manifest, **service workers only work in the production build, not in development**. To test it locally, use `vite preview`.
2 changes: 1 addition & 1 deletion documentation/docs/10-adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ To create a simple Node server, install the [`@sveltejs/adapter-node`](https://g
+import adapter from '@sveltejs/adapter-node';
```

With this, [svelte-kit build](/docs/cli#svelte-kit-build) will generate a self-contained Node app inside the `build` directory. You can pass options to adapters, such as customising the output directory:
With this, `vite build` will generate a self-contained Node app inside the `build` directory. You can pass options to adapters, such as customising the output directory:

```diff
/// file: svelte.config.js
Expand Down
46 changes: 10 additions & 36 deletions documentation/docs/13-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,22 @@
title: Command Line Interface
---

SvelteKit includes a command line interface for building and running your app.
SvelteKit projects use [Vite](https://vitejs.dev), meaning you'll mostly use its CLI (albeit via `npm run dev/build/preview` scripts):

In the default project template `svelte-kit dev`, `svelte-kit build` and `svelte-kit preview` are aliased as `npm run dev`, `npm run build` and `npm run preview` respectively. You can also invoke the CLI with [npx](https://www.npmjs.com/package/npx):
- `vite dev` — start a development server
- `vite build` — build a production version of your app
- `vite preview` — run the production version locally

```bash
npx svelte-kit dev
```

### svelte-kit dev

Starts a development server. It accepts the following options:

- `-p`/`--port` — which port to start the server on
- `-o`/`--open` — open a browser tab once the server starts
- `--host` — expose the server to the network.
- `--https` — launch an HTTPS server using a self-signed certificate. Useful for testing HTTPS-only features on an external device

> This command will fail if the specified (or default) port is unavailable. To use an alternative port instead of failing, set the [`config.kit.vite.server.strictPort`](/docs/configuration#vite) option to `false`.
### svelte-kit build

Builds a production version of your app, and runs your adapter if you have one specified in your [config](/docs/configuration). It accepts the following option:

- `--verbose` — log more detail

After building the app, you can reference the documentation of your chosen [adapter](/docs/adapters) and hosting platform for specific instructions on how to serve your app.

### svelte-kit preview

After you've built your app with `svelte-kit build`, you can start the production version (irrespective of any adapter that has been applied) locally with `svelte-kit preview`. This is intended for testing the production build locally, **not for serving your app**, for which you should always use an [adapter](/docs/adapters).

Like `svelte-kit dev`, it accepts the following options:

- `-p`/`--port`
- `-o`/`--open`
- `--host`
- `--https`
However SvelteKit includes its own CLI for creating distributable packages and initialising your project:

### svelte-kit package

> `svelte-kit package` is currently experimental and is not subject to Semantic Versioning rules. Non-backward compatible changes may occur in any future release.
For package authors, see [packaging](/docs/packaging). `svelte-kit package` accepts the following options:
See [packaging](/docs/packaging). `svelte-kit package` accepts the following options:

- `-w`/`--watch` — watch files in `src/lib` for changes and rebuild the package

### svelte-kit sync

`svelte-kit sync` creates the generated files for your project such as types and a `tsconfig.json`. When you create a new project, it is listed as the `prepare` script and will be run automatically as part of the npm lifecycle, so you should not ordinarily have to run this command.
2 changes: 1 addition & 1 deletion documentation/docs/14-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default config;

### adapter

Required when running `svelte-kit build` and determines how the output is converted for different platforms. See [Adapters](/docs/adapters).
Run when executing `vite build` and determines how the output is converted for different platforms. See [Adapters](/docs/adapters).

### alias

Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/15-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Others are required for SvelteKit to work properly, and should also be left unto
// markup, so we need this
"preserveValueImports": true,

// This ensures both `svelte-kit build`
// This ensures both `vite build`
// and `svelte-kit package` work correctly
"lib": ["esnext", "DOM"],
"moduleResolution": "node",
Expand Down
8 changes: 4 additions & 4 deletions documentation/docs/80-migrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ Remove `sapper` from your `devDependencies` and replace it with `@sveltejs/kit`

Any scripts that reference `sapper` should be updated:

- `sapper build` should become [`svelte-kit build`](/docs/cli#svelte-kit-build) using the Node [adapter](/docs/adapters)
- `sapper export` should become [`svelte-kit build`](/docs/cli#svelte-kit-build) using the static [adapter](/docs/adapters)
- `sapper dev` should become [`svelte-kit dev`](/docs/cli#svelte-kit-dev)
- `sapper build` should become `vite build` using the Node [adapter](/docs/adapters)
- `sapper export` should become `vite build` using the static [adapter](/docs/adapters)
- `sapper dev` should become `vite dev`
- `node __sapper__/build` should become `node build`

### Project files
Expand Down Expand Up @@ -191,4 +191,4 @@ export async function handle({ event, resolve }) {
}
```

Note that `prerendering` is `false` when using `svelte-kit preview` to test the production build of the site, so to verify the results of minifying, you'll need to inspect the built HTML files directly.
Note that `prerendering` is `false` when using `vite preview` to test the production build of the site, so to verify the results of minifying, you'll need to inspect the built HTML files directly.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"homepage": "https://github.com/sveltejs/kit#readme",
"devDependencies": {
"@changesets/cli": "^2.22.0",
"@rollup/plugin-commonjs": "^21.1.0",
"@rollup/plugin-commonjs": "^22.0.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@sveltejs/eslint-config": "github:sveltejs/eslint-config#v5.8.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"devDependencies": {
"@netlify/functions": "^1.0.0",
"@rollup/plugin-commonjs": "^21.1.0",
"@rollup/plugin-commonjs": "^22.0.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"@sveltejs/kit": "workspace:*",
Expand Down
3 changes: 2 additions & 1 deletion packages/adapter-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"sirv": "^2.0.2",
"svelte": "^3.48.0",
"typescript": "^4.7.2",
"uvu": "^0.5.3"
"uvu": "^0.5.3",
"vite": "^2.9.13"
}
}
11 changes: 6 additions & 5 deletions packages/adapter-static/test/apps/prerendered/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "../../../../kit/svelte-kit.js dev",
"build": "../../../../kit/svelte-kit.js build",
"start": "../../../../kit/svelte-kit.js start"
"dev": "vite dev",
"build": "vite build",
"start": "vite start"
},
"devDependencies": {
"@sveltejs/kit": "next",
"svelte": "^3.48.0"
"@sveltejs/kit": "workspace:*",
"svelte": "^3.48.0",
"vite": "^2.9.13"
},
"type": "module"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ const config = {

prerender: {
default: true
},

vite: {
build: {
minify: false
}
}
}
};
Expand Down
11 changes: 11 additions & 0 deletions packages/adapter-static/test/apps/prerendered/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { sveltekit } = await import(process.env.SVELTEKIT_PLUGIN);

/** @type {import('vite').UserConfig} */
const config = {
build: {
minify: false
},
plugins: [sveltekit()]
};

export default config;
11 changes: 6 additions & 5 deletions packages/adapter-static/test/apps/spa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "../../../../kit/svelte-kit.js dev",
"build": "../../../../kit/svelte-kit.js build",
"dev": "vite dev",
"build": "vite build",
"start": "sirv -s 200.html build"
},
"devDependencies": {
"@sveltejs/adapter-node": "next",
"@sveltejs/kit": "next",
"@sveltejs/adapter-node": "workspace:*",
"@sveltejs/kit": "workspace:*",
"sirv-cli": "^2.0.2",
"svelte": "^3.48.0"
"svelte": "^3.48.0",
"vite": "^2.9.13"
},
"type": "module"
}
8 changes: 1 addition & 7 deletions packages/adapter-static/test/apps/spa/svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ const config = {
kit: {
adapter: adapter({
fallback: '200.html'
}),

vite: {
build: {
minify: false
}
}
})
}
};

Expand Down
11 changes: 11 additions & 0 deletions packages/adapter-static/test/apps/spa/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { sveltekit } = await import(process.env.SVELTEKIT_PLUGIN);

/** @type {import('vite').UserConfig} */
const config = {
build: {
minify: false
},
plugins: [sveltekit()]
};

export default config;
6 changes: 4 additions & 2 deletions packages/adapter-static/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ export function run(app, callback) {
try {
const cwd = fileURLToPath(new URL(`apps/${app}`, import.meta.url));
const mode = process.env.CI ? 'dist' : 'src';
const cli_path = fileURLToPath(new URL(`../../kit/${mode}/cli.js`, import.meta.url));

process.env.SVELTEKIT_PLUGIN =
mode === 'dist' ? '@sveltejs/kit/vite' : '../../../../kit/src/vite/index.js';

rimraf(`${cwd}/build`);

await spawn(`"${process.execPath}" ${cli_path} build`, {
await spawn('npm run build', {
cwd,
stdio: 'inherit',
shell: true
Expand Down
9 changes: 5 additions & 4 deletions packages/create-svelte/templates/default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
"version": "0.0.2-next.0",
"private": true,
"scripts": {
"dev": "svelte-kit dev",
"build": "svelte-kit build --verbose",
"dev": "vite dev",
"build": "vite build",
"package": "svelte-kit package",
"preview": "svelte-kit preview"
"preview": "vite preview"
},
"devDependencies": {
"@sveltejs/adapter-auto": "workspace:*",
"@sveltejs/kit": "workspace:*",
"svelte": "^3.48.0",
"svelte-preprocess": "^4.10.6",
"typescript": "^4.7.2"
"typescript": "^4.7.2",
"vite": "^2.9.13"
},
"type": "module",
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
"name": "~TODO~",
"version": "0.0.1",
"scripts": {
"dev": "svelte-kit dev",
"build": "svelte-kit build",
"dev": "vite dev",
"build": "vite build",
"package": "svelte-kit package",
"preview": "svelte-kit preview",
"preview": "vite preview",
"prepare": "svelte-kit sync"
},
"devDependencies": {
"@sveltejs/adapter-auto": "next",
"@sveltejs/kit": "next",
"svelte": "^3.46.0"
"svelte": "^3.46.0",
"vite": "^2.9.13"
},
"type": "module",
"dependencies": {
Expand Down
8 changes: 8 additions & 0 deletions packages/create-svelte/templates/default/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { sveltekit } from '@sveltejs/kit/vite';

/** @type {import('vite').UserConfig} */
const config = {
plugins: [sveltekit()]
};

export default config;
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
"name": "~TODO~",
"version": "0.0.1",
"scripts": {
"dev": "svelte-kit dev",
"build": "svelte-kit build",
"dev": "vite dev",
"build": "vite build",
"package": "svelte-kit package",
"preview": "svelte-kit preview",
"preview": "vite preview",
"prepare": "svelte-kit sync"
},
"devDependencies": {
"@sveltejs/adapter-auto": "workspace:*",
"@sveltejs/kit": "workspace:*",
"svelte": "^3.44.0"
"svelte": "^3.44.0",
"vite": "^2.9.13"
},
"type": "module"
}
8 changes: 8 additions & 0 deletions packages/create-svelte/templates/skeleton/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { sveltekit } from '@sveltejs/kit/vite';

/** @type {import('vite').UserConfig} */
const config = {
plugins: [sveltekit()]
};

export default config;
Loading

0 comments on commit 2e2719c

Please sign in to comment.