Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[breaking] graduate @sveltejs/kit/vite from experimental and require vite.config.js #5332

Merged
merged 52 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
a498383
[breaking] graduate @sveltejs/kit/vite from experimental
benmccann Jun 30, 2022
ad2505b
update site and tests to use vite.config.js
benmccann Jul 1, 2022
f2dfd87
Add vite.config.js to the create-svelte templates
benmccann Jul 1, 2022
8648f81
[breaking] require vite.config.js
benmccann Jul 1, 2022
b6b9208
turbo can go to hell
benmccann Jul 1, 2022
65e39cb
wtf pnpm
benmccann Jul 1, 2022
aaa5696
revert b6b9208be5cd73ba15873a82c87568ec947a127f
Rich-Harris Jul 1, 2022
662f16b
fix some turbo config
Rich-Harris Jul 1, 2022
f4cc6e5
lint
Rich-Harris Jul 1, 2022
323c5be
check
Rich-Harris Jul 1, 2022
7081b47
Update packages/kit/src/cli.js
benmccann Jul 1, 2022
95d05aa
[breaking] switch to vite CLI for dev, build, and preview commands
benmccann Jul 1, 2022
6a12cd9
Clarify message
benmccann Jul 1, 2022
ff1385d
merge master
benmccann Jul 1, 2022
7acab73
more updates to test projects
benmccann Jul 1, 2022
46c4b0c
remove svelte-kit dev/build/preview commands
Rich-Harris Jul 1, 2022
cd43e96
a few more fixes
benmccann Jul 1, 2022
78184b1
migration instructions
Rich-Harris Jul 1, 2022
ad8a9a4
Merge branch 'vite-final' of github.com:sveltejs/kit into vite-final
Rich-Harris Jul 1, 2022
7a480e3
lint
Rich-Harris Jul 1, 2022
c447e51
fix adapter-static tests
Rich-Harris Jul 1, 2022
eb62733
docs
benmccann Jul 1, 2022
ba70c91
Merge branch 'vite-final' of github.com:sveltejs/kit into vite-final
benmccann Jul 1, 2022
5771890
update lockfile, not sure how it got borked
Rich-Harris Jul 1, 2022
03e0cf8
lockfile
benmccann Jul 1, 2022
0ddb508
merge
Rich-Harris Jul 1, 2022
9e6b540
doc typos
benmccann Jul 1, 2022
efd7a2f
bump undici
benmccann Jul 2, 2022
997480d
bump @rollup/plugin-commonjs
benmccann Jul 2, 2022
fb02207
fix config validation
benmccann Jul 2, 2022
41c0ebe
fix #5308
benmccann Jul 2, 2022
aa76235
adapter-static tests
benmccann Jul 2, 2022
263e4c4
update svelte-kit sync docs
benmccann Jul 2, 2022
23692ab
update svelte-kit package docs
benmccann Jul 2, 2022
72432bb
Revert "adapter-static tests"
Rich-Harris Jul 2, 2022
9ece16a
fix workspace/prepare scripts
Rich-Harris Jul 2, 2022
c4b10cd
Revert "fix workspace/prepare scripts"
benmccann Jul 3, 2022
b552dbd
Revert "Revert "adapter-static tests""
benmccann Jul 3, 2022
e251509
try something else
benmccann Jul 3, 2022
422e7ac
remove debug line
benmccann Jul 3, 2022
ad0890c
Merge branch 'master' into vite-final
Rich-Harris Jul 5, 2022
5b2eebd
try using edge functions
benmccann Jul 5, 2022
c29c1a5
Revert "try using edge functions"
benmccann Jul 5, 2022
7166ccd
remove unused file
Rich-Harris Jul 5, 2022
15a4a0b
Merge branch 'vite-final' of github.com:sveltejs/kit into vite-final
Rich-Harris Jul 5, 2022
3083aa4
update gitignore so we can run vc build locally to diagnose hanging
Rich-Harris Jul 5, 2022
3c97046
tweak CLI docs
Rich-Harris Jul 5, 2022
91363e8
trying this once more
Rich-Harris Jul 5, 2022
fac7109
doh
Rich-Harris Jul 5, 2022
ac8ce4b
use workspace dependencies
Rich-Harris Jul 5, 2022
abd327e
ugh lockfile
Rich-Harris Jul 5, 2022
12a03e2
use src code locally, dist in CI
Rich-Harris Jul 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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