Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Aug 16, 2022
1 parent 6f355ea commit ad7aaaa
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions packages/kit/src/vite/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,23 @@ export async function dev(vite, vite_config, svelte_config, illegal_imports) {
}
});

return () => {
return async () => {
const serve_static_middleware = vite.middlewares.stack.find(
(middleware) =>
/** @type {function} */ (middleware.handle).name === 'viteServeStaticMiddleware'
);

remove_static_middlewares(vite.middlewares);

const runtime_base = path.relative('.', runtime_directory);

const { set_private_env } = await vite.ssrLoadModule(`${runtime_base}/env-private.js`);
const { set_public_env } = await vite.ssrLoadModule(`${runtime_base}/env-public.js`);

const env = get_env(vite_config.mode, svelte_config.kit.env.publicPrefix);
set_private_env(env.private);
set_public_env(env.public);

vite.middlewares.use(async (req, res) => {
try {
const base = `${vite.config.server.https ? 'https' : 'http'}://${
Expand All @@ -320,20 +329,6 @@ export async function dev(vite, vite_config, svelte_config, illegal_imports) {
);
}

// For some reason using runtime_prefix here is buggy, since Vite will later load the modules
// again with a slightly different url (with the drive letter) on windows
const runtime_base = `/@fs${
// Windows/Linux separation - Windows starts with a drive letter, we need a / in front there
runtime_directory.startsWith('/') ? '' : '/'
}${runtime_directory}`;

const { set_private_env } = await vite.ssrLoadModule(`${runtime_base}/env-private.js`);
const { set_public_env } = await vite.ssrLoadModule(`${runtime_base}/env-public.js`);

const env = get_env(vite_config.mode, svelte_config.kit.env.publicPrefix);
set_private_env(env.private);
set_public_env(env.public);

/** @type {Partial<import('types').Hooks>} */
const user_hooks = resolve_entry(svelte_config.kit.files.hooks)
? await vite.ssrLoadModule(`/${svelte_config.kit.files.hooks}`)
Expand Down

0 comments on commit ad7aaaa

Please sign in to comment.