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

[chore] provide Vite config via plugin #5073

Merged
merged 5 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/cyan-files-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[chore] provide Vite config via plugin
53 changes: 38 additions & 15 deletions packages/kit/src/cli.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import sade from 'sade';
import colors from 'kleur';
import chokidar from 'chokidar';
import fs from 'fs';
import colors from 'kleur';
import { relative } from 'path';
import * as ports from 'port-authority';
import chokidar from 'chokidar';
import sade from 'sade';
import * as vite from 'vite';
import { load_config } from './core/config/index.js';
import { networkInterfaces, release } from 'os';
import { coalesce_to_error } from './utils/error.js';
Expand Down Expand Up @@ -62,35 +63,57 @@ prog
let close;

async function start() {
const { dev } = await import('./core/dev/index.js');
const svelte_config = await load_config();
const { plugins } = await import('./core/dev/plugin.js');
const vite_config = await svelte_config.kit.vite();

/** @type {import('vite').UserConfig} */
const config = {
plugins: [...(vite_config.plugins || []), plugins(svelte_config)]
};
config.server = {};

// optional config from command-line flags
// these should take precedence, but not print conflict warnings
if (host) {
config.server.host = host;
}

const { server, config } = await dev({
port,
host,
https
});
// if https is already enabled then do nothing. it could be an object and we
// don't want to overwrite with a boolean
if (https && !vite_config?.server?.https) {
config.server.https = https;
}

if (port) {
config.server.port = port;
}

const server = await vite.createServer(config);
await server.listen(port);

const address_info = /** @type {import('net').AddressInfo} */ (
/** @type {import('http').Server} */ (server.httpServer).address()
);

const vite_config = server.config;
const resolved_config = server.config;

welcome({
port: address_info.port,
host: address_info.address,
https: !!(https || vite_config.server.https),
open: first && (open || !!vite_config.server.open),
base: config.kit.paths.base,
loose: vite_config.server.fs.strict === false,
allow: vite_config.server.fs.allow
https: !!(https || resolved_config.server.https),
open: first && (open || !!resolved_config.server.open),
base: svelte_config.kit.paths.base,
loose: resolved_config.server.fs.strict === false,
allow: resolved_config.server.fs.allow
});

first = false;

return server.close;
}

// TODO: we should probably replace this with something like vite-plugin-restart
async function relaunch() {
const id = uid;
relaunching = true;
Expand Down
104 changes: 0 additions & 104 deletions packages/kit/src/core/dev/index.js

This file was deleted.

Loading