Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
We exposed the
preview
as experimental in #5014. SvelteKit didn't end up using it, so we are still able to review this API without downstream issues before stabilizing the feature.We have also been merging some PRs that added options in the second parameter (initially it was only the port), and others that used the external inline config (
open
,https
,strictPort
). We now have some in both places (host
, after #5389, that we merged to fix the logging of URLs as this was using the config instead of thehost
in the second parameter options of preview).This PR aligns the
preview
API with thecreateServer
andbuild
functions. In both cases, they take anInlineConfig
and do the resolution of the config internally. The method also returns a newPreviewServer
object that exposes theconfig
,httpServer
andprintUrls
following the same pattern we use forViteDevServer
. This would also let us extend the preview server in the future if needed.I'm sending the PR so we can discuss details about the API. Options:
userConfig.server
andresolvedConfig.server
following the current design. This is ok because users normally want to share the configuration for both servers (cors
,https
,proxy
, etc). The only config that needs to be overwritten isport
. This PR proposes that we should let the user change it using theinlineConfig
.preview(inlineconfig, port=5000)
. This will be closer to the original function.userConfig.preview: { port: 5000, ... }
config option and aresolvedConfig.preview
that has the resolved info for the preview server. This PR reorders the interface for theServerOptions
placing every Http Server Options on the top so it is easier to know what is shared between the dev and preview servers. We could have anHttpServerOptions
interface that is shared and a newPreviewServerOptions
. The preview server would default to the options in dev server forhost
,strictPort
,https
,cors
,proxy
(and maybeopen
) but not forport
. This would allow the user to define the preview port invite.config.js
instead of in thepackage.json
script. It could be more clear also to see in theResolvedConfig
the resolved HTTP server options for the dev server and the preview server separately.What is the purpose of this pull request?