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

Shared config object is mutated #5308

Closed
benmccann opened this issue Jun 28, 2022 · 0 comments · Fixed by #5332
Closed

Shared config object is mutated #5308

benmccann opened this issue Jun 28, 2022 · 0 comments · Fixed by #5332
Labels
bug Something isn't working

Comments

@benmccann
Copy link
Member

benmccann commented Jun 28, 2022

Describe the bug

SvelteKit's vite/index.js stores the config in vite_user_config and passes it into multiple builds. Vite mutates the config causing unexpected values for latter builds. This doesn't seem to be an issue for most users, but does cause issues with vite-plugin-pwa

Reproduction

Update svelte.config.js for the site to the one below. Note that you need to comment out SvelteKit's process.exit for the Vite plugin to be invoked

import * as path from 'path';
import adapter from '@sveltejs/adapter-auto';
import { imagetools } from 'vite-imagetools';

let viteConfig;

/** @type {import('@sveltejs/kit').Config} */
const config = {
	kit: {
		adapter: adapter(),

		prerender: {
			default: true,
			entries: ['*', '/content.json']
		},

		vite: {
			plugins: [imagetools(), {
				name: "vite-plugin-pwa",
				enforce: "post",
				apply: "build",
				async configResolved(config) {
					viteConfig = config;
				},
				async closeBundle() {
					console.log(`IS SSR? ${viteConfig.build.ssr}`)
				}
			}],

			resolve: {
				alias: {
					$img: path.resolve('src/images')
				}
			},

			server: {
				fs: {
					strict: false
				}
			}
		}
	}
};

export default config;

Suggested Solution

The config above isn't one that can be cloned. Instead we need to do something like leave vite-plugin-svelte-kit in place, but make writeBundle a no-op unless it's the client build (or equivalently split the config stuff out into a separate plugin that's used for the server build as well)

System Info

`master`

Severity

Prevents https://github.com/userquin/pwa-sveltekit-vite from working

Additional Information

No response

@benmccann benmccann added the bug Something isn't working label Jun 28, 2022
benmccann added a commit that referenced this issue Jul 2, 2022
Rich-Harris added a commit that referenced this issue Jul 5, 2022
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant