@sveltejs/kit 1.0.0-next.26 → 1.0.0-next.260
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -9
- package/assets/app/env.js +20 -0
- package/assets/app/navigation.js +79 -0
- package/assets/app/paths.js +1 -0
- package/assets/app/stores.js +97 -0
- package/assets/chunks/utils.js +13 -0
- package/assets/client/singletons.js +21 -0
- package/assets/client/start.js +1493 -0
- package/assets/components/error.svelte +18 -2
- package/assets/env.js +8 -0
- package/assets/paths.js +13 -0
- package/assets/server/index.js +2664 -0
- package/dist/chunks/amp_hook.js +56 -0
- package/dist/chunks/build.js +658 -0
- package/dist/chunks/cert.js +28154 -0
- package/dist/chunks/index.js +467 -0
- package/dist/chunks/index2.js +836 -0
- package/dist/chunks/index3.js +638 -0
- package/dist/chunks/index4.js +115 -0
- package/dist/chunks/index5.js +860 -0
- package/dist/chunks/index6.js +170 -0
- package/dist/chunks/index7.js +15582 -0
- package/dist/chunks/index8.js +4207 -0
- package/dist/chunks/misc.js +3 -0
- package/dist/chunks/multipart-parser.js +449 -0
- package/dist/cli.js +1128 -84
- package/dist/hooks.js +28 -0
- package/dist/install-fetch.js +6518 -0
- package/dist/node.js +95 -0
- package/package.json +95 -54
- package/svelte-kit.js +2 -0
- package/types/ambient-modules.d.ts +208 -0
- package/types/app.d.ts +35 -0
- package/types/config.d.ts +176 -0
- package/types/csp.d.ts +115 -0
- package/types/endpoint.d.ts +39 -0
- package/types/helper.d.ts +23 -0
- package/types/hooks.d.ts +34 -0
- package/types/index.d.ts +10 -0
- package/types/internal.d.ts +260 -0
- package/types/page.d.ts +33 -0
- package/CHANGELOG.md +0 -312
- package/assets/runtime/app/navigation.js +0 -23
- package/assets/runtime/app/navigation.js.map +0 -1
- package/assets/runtime/app/paths.js +0 -2
- package/assets/runtime/app/paths.js.map +0 -1
- package/assets/runtime/app/stores.js +0 -78
- package/assets/runtime/app/stores.js.map +0 -1
- package/assets/runtime/internal/singletons.js +0 -15
- package/assets/runtime/internal/singletons.js.map +0 -1
- package/assets/runtime/internal/start.js +0 -591
- package/assets/runtime/internal/start.js.map +0 -1
- package/assets/runtime/utils-85ebcc60.js +0 -18
- package/assets/runtime/utils-85ebcc60.js.map +0 -1
- package/dist/api.js +0 -44
- package/dist/api.js.map +0 -1
- package/dist/build.js +0 -246
- package/dist/build.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/colors.js +0 -37
- package/dist/colors.js.map +0 -1
- package/dist/create_app.js +0 -580
- package/dist/create_app.js.map +0 -1
- package/dist/index.js +0 -367
- package/dist/index.js.map +0 -1
- package/dist/index2.js +0 -12035
- package/dist/index2.js.map +0 -1
- package/dist/index3.js +0 -547
- package/dist/index3.js.map +0 -1
- package/dist/index4.js +0 -74
- package/dist/index4.js.map +0 -1
- package/dist/index5.js +0 -464
- package/dist/index5.js.map +0 -1
- package/dist/index6.js +0 -727
- package/dist/index6.js.map +0 -1
- package/dist/logging.js +0 -43
- package/dist/logging.js.map +0 -1
- package/dist/package.js +0 -432
- package/dist/package.js.map +0 -1
- package/dist/renderer.js +0 -2403
- package/dist/renderer.js.map +0 -1
- package/dist/standard.js +0 -101
- package/dist/standard.js.map +0 -1
- package/dist/utils.js +0 -54
- package/dist/utils.js.map +0 -1
- package/svelte-kit +0 -3
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
import path__default from 'path';
|
|
2
|
+
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
|
3
|
+
import vite from 'vite';
|
|
4
|
+
import { c as create_manifest_data, a as create_app, d as deep_merge } from './index2.js';
|
|
5
|
+
import { r as runtime, S as SVELTE_KIT_ASSETS, a as resolve_entry, $, b as SVELTE_KIT, l as load_template, c as coalesce_to_error, g as get_mime_lookup, d as copy_assets, e as get_aliases, p as print_config_conflicts } from '../cli.js';
|
|
6
|
+
import fs__default from 'fs';
|
|
7
|
+
import { URL } from 'url';
|
|
8
|
+
import { s as sirv } from './build.js';
|
|
9
|
+
import { __fetch_polyfill } from '../install-fetch.js';
|
|
10
|
+
import { getRequest, setResponse } from '../node.js';
|
|
11
|
+
import { sequence } from '../hooks.js';
|
|
12
|
+
import './misc.js';
|
|
13
|
+
import 'sade';
|
|
14
|
+
import 'child_process';
|
|
15
|
+
import 'net';
|
|
16
|
+
import 'os';
|
|
17
|
+
import 'querystring';
|
|
18
|
+
import 'node:http';
|
|
19
|
+
import 'node:https';
|
|
20
|
+
import 'node:zlib';
|
|
21
|
+
import 'node:stream';
|
|
22
|
+
import 'node:util';
|
|
23
|
+
import 'node:url';
|
|
24
|
+
import 'stream';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {import('types/config').ValidatedConfig} config
|
|
28
|
+
* @param {string} cwd
|
|
29
|
+
* @returns {Promise<import('vite').Plugin>}
|
|
30
|
+
*/
|
|
31
|
+
async function create_plugin(config, cwd) {
|
|
32
|
+
/** @type {import('types/hooks').Handle} */
|
|
33
|
+
let amp;
|
|
34
|
+
|
|
35
|
+
if (config.kit.amp) {
|
|
36
|
+
process.env.VITE_SVELTEKIT_AMP = 'true';
|
|
37
|
+
amp = (await import('./amp_hook.js')).handle;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
process.env.VITE_SVELTEKIT_APP_VERSION_POLL_INTERVAL = '0';
|
|
41
|
+
|
|
42
|
+
/** @type {import('types/internal').Respond} */
|
|
43
|
+
const respond = (await import(`${runtime}/server/index.js`)).respond;
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
name: 'vite-plugin-svelte-kit',
|
|
47
|
+
|
|
48
|
+
configureServer(vite) {
|
|
49
|
+
__fetch_polyfill();
|
|
50
|
+
|
|
51
|
+
/** @type {import('types/app').SSRManifest} */
|
|
52
|
+
let manifest;
|
|
53
|
+
|
|
54
|
+
function update_manifest() {
|
|
55
|
+
const manifest_data = create_manifest_data({ config, cwd });
|
|
56
|
+
|
|
57
|
+
create_app({ manifest_data, output: `${SVELTE_KIT}/generated`, cwd });
|
|
58
|
+
|
|
59
|
+
manifest = {
|
|
60
|
+
appDir: config.kit.appDir,
|
|
61
|
+
assets: new Set(manifest_data.assets.map((asset) => asset.file)),
|
|
62
|
+
_: {
|
|
63
|
+
mime: get_mime_lookup(manifest_data),
|
|
64
|
+
entry: {
|
|
65
|
+
file: `/@fs${runtime}/client/start.js`,
|
|
66
|
+
css: [],
|
|
67
|
+
js: []
|
|
68
|
+
},
|
|
69
|
+
nodes: manifest_data.components.map((id) => {
|
|
70
|
+
return async () => {
|
|
71
|
+
const url = id.startsWith('..') ? `/@fs${path__default.posix.resolve(id)}` : `/${id}`;
|
|
72
|
+
|
|
73
|
+
const module = /** @type {import('types/internal').SSRComponent} */ (
|
|
74
|
+
await vite.ssrLoadModule(url)
|
|
75
|
+
);
|
|
76
|
+
const node = await vite.moduleGraph.getModuleByUrl(url);
|
|
77
|
+
|
|
78
|
+
if (!node) throw new Error(`Could not find node for ${url}`);
|
|
79
|
+
|
|
80
|
+
const deps = new Set();
|
|
81
|
+
find_deps(node, deps);
|
|
82
|
+
|
|
83
|
+
/** @type {Record<string, string>} */
|
|
84
|
+
const styles = {};
|
|
85
|
+
|
|
86
|
+
for (const dep of deps) {
|
|
87
|
+
const parsed = new URL(dep.url, 'http://localhost/');
|
|
88
|
+
const query = parsed.searchParams;
|
|
89
|
+
|
|
90
|
+
// TODO what about .scss files, etc?
|
|
91
|
+
if (
|
|
92
|
+
dep.file.endsWith('.css') ||
|
|
93
|
+
(query.has('svelte') && query.get('type') === 'style')
|
|
94
|
+
) {
|
|
95
|
+
try {
|
|
96
|
+
const mod = await vite.ssrLoadModule(dep.url);
|
|
97
|
+
styles[dep.url] = mod.default;
|
|
98
|
+
} catch {
|
|
99
|
+
// this can happen with dynamically imported modules, I think
|
|
100
|
+
// because the Vite module graph doesn't distinguish between
|
|
101
|
+
// static and dynamic imports? TODO investigate, submit fix
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
module,
|
|
108
|
+
entry: url.endsWith('.svelte') ? url : url + '?import',
|
|
109
|
+
css: [],
|
|
110
|
+
js: [],
|
|
111
|
+
styles
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
}),
|
|
115
|
+
routes: manifest_data.routes.map((route) => {
|
|
116
|
+
if (route.type === 'page') {
|
|
117
|
+
return {
|
|
118
|
+
type: 'page',
|
|
119
|
+
pattern: route.pattern,
|
|
120
|
+
params: get_params(route.params),
|
|
121
|
+
shadow: route.shadow
|
|
122
|
+
? async () => {
|
|
123
|
+
const url = path__default.resolve(cwd, /** @type {string} */ (route.shadow));
|
|
124
|
+
return await vite.ssrLoadModule(url);
|
|
125
|
+
}
|
|
126
|
+
: null,
|
|
127
|
+
a: route.a.map((id) => manifest_data.components.indexOf(id)),
|
|
128
|
+
b: route.b.map((id) => manifest_data.components.indexOf(id))
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
type: 'endpoint',
|
|
134
|
+
pattern: route.pattern,
|
|
135
|
+
params: get_params(route.params),
|
|
136
|
+
load: async () => {
|
|
137
|
+
const url = path__default.resolve(cwd, route.file);
|
|
138
|
+
return await vite.ssrLoadModule(url);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
update_manifest();
|
|
147
|
+
|
|
148
|
+
vite.watcher.on('add', update_manifest);
|
|
149
|
+
vite.watcher.on('remove', update_manifest);
|
|
150
|
+
|
|
151
|
+
const assets = config.kit.paths.assets ? SVELTE_KIT_ASSETS : config.kit.paths.base;
|
|
152
|
+
const asset_server = sirv(config.kit.files.assets, {
|
|
153
|
+
dev: true,
|
|
154
|
+
etag: true,
|
|
155
|
+
maxAge: 0,
|
|
156
|
+
extensions: []
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
return () => {
|
|
160
|
+
remove_html_middlewares(vite.middlewares);
|
|
161
|
+
|
|
162
|
+
vite.middlewares.use(async (req, res) => {
|
|
163
|
+
try {
|
|
164
|
+
if (!req.url || !req.method) throw new Error('Incomplete request');
|
|
165
|
+
|
|
166
|
+
const base = `${vite.config.server.https ? 'https' : 'http'}://${req.headers.host}`;
|
|
167
|
+
|
|
168
|
+
const decoded = decodeURI(new URL(base + req.url).pathname);
|
|
169
|
+
|
|
170
|
+
if (decoded.startsWith(assets)) {
|
|
171
|
+
const pathname = decoded.slice(assets.length);
|
|
172
|
+
const file = config.kit.files.assets + pathname;
|
|
173
|
+
|
|
174
|
+
if (fs__default.existsSync(file) && !fs__default.statSync(file).isDirectory()) {
|
|
175
|
+
req.url = encodeURI(pathname); // don't need query/hash
|
|
176
|
+
asset_server(req, res);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (req.url === '/favicon.ico') return not_found(res);
|
|
182
|
+
|
|
183
|
+
if (!decoded.startsWith(config.kit.paths.base)) return not_found(res);
|
|
184
|
+
|
|
185
|
+
/** @type {Partial<import('types/internal').Hooks>} */
|
|
186
|
+
const user_hooks = resolve_entry(config.kit.files.hooks)
|
|
187
|
+
? await vite.ssrLoadModule(`/${config.kit.files.hooks}`)
|
|
188
|
+
: {};
|
|
189
|
+
|
|
190
|
+
const handle = user_hooks.handle || (({ event, resolve }) => resolve(event));
|
|
191
|
+
|
|
192
|
+
/** @type {import('types/internal').Hooks} */
|
|
193
|
+
const hooks = {
|
|
194
|
+
// @ts-expect-error this picks up types that belong to the tests
|
|
195
|
+
getSession: user_hooks.getSession || (() => ({})),
|
|
196
|
+
handle: amp ? sequence(amp, handle) : handle,
|
|
197
|
+
handleError:
|
|
198
|
+
user_hooks.handleError ||
|
|
199
|
+
(({ /** @type {Error & { frame?: string }} */ error }) => {
|
|
200
|
+
console.error($.bold().red(error.message));
|
|
201
|
+
if (error.frame) {
|
|
202
|
+
console.error($.gray(error.frame));
|
|
203
|
+
}
|
|
204
|
+
if (error.stack) {
|
|
205
|
+
console.error($.gray(error.stack));
|
|
206
|
+
}
|
|
207
|
+
}),
|
|
208
|
+
externalFetch: user_hooks.externalFetch || fetch
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
if (/** @type {any} */ (hooks).getContext) {
|
|
212
|
+
// TODO remove this for 1.0
|
|
213
|
+
throw new Error(
|
|
214
|
+
'The getContext hook has been removed. See https://kit.svelte.dev/docs#hooks'
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (/** @type {any} */ (hooks).serverFetch) {
|
|
219
|
+
// TODO remove this for 1.0
|
|
220
|
+
throw new Error('The serverFetch hook has been renamed to externalFetch.');
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const root = (await vite.ssrLoadModule(`/${SVELTE_KIT}/generated/root.svelte`)).default;
|
|
224
|
+
const paths = await vite.ssrLoadModule(
|
|
225
|
+
true ? `/${SVELTE_KIT}/runtime/paths.js` : `/@fs${runtime}/paths.js`
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
paths.set_paths({
|
|
229
|
+
base: config.kit.paths.base,
|
|
230
|
+
assets
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
let request;
|
|
234
|
+
|
|
235
|
+
try {
|
|
236
|
+
request = await getRequest(base, req);
|
|
237
|
+
} catch (/** @type {any} */ err) {
|
|
238
|
+
res.statusCode = err.status || 400;
|
|
239
|
+
return res.end(err.reason || 'Invalid request body');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const template = load_template(cwd, config);
|
|
243
|
+
|
|
244
|
+
const rendered = await respond(request, {
|
|
245
|
+
amp: config.kit.amp,
|
|
246
|
+
csp: config.kit.csp,
|
|
247
|
+
dev: true,
|
|
248
|
+
floc: config.kit.floc,
|
|
249
|
+
get_stack: (error) => {
|
|
250
|
+
vite.ssrFixStacktrace(error);
|
|
251
|
+
return error.stack;
|
|
252
|
+
},
|
|
253
|
+
handle_error: (error, event) => {
|
|
254
|
+
vite.ssrFixStacktrace(error);
|
|
255
|
+
hooks.handleError({
|
|
256
|
+
error,
|
|
257
|
+
event,
|
|
258
|
+
|
|
259
|
+
// TODO remove for 1.0
|
|
260
|
+
// @ts-expect-error
|
|
261
|
+
get request() {
|
|
262
|
+
throw new Error(
|
|
263
|
+
'request in handleError has been replaced with event. See https://github.com/sveltejs/kit/pull/3384 for details'
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
},
|
|
268
|
+
hooks,
|
|
269
|
+
hydrate: config.kit.browser.hydrate,
|
|
270
|
+
manifest,
|
|
271
|
+
method_override: config.kit.methodOverride,
|
|
272
|
+
paths: {
|
|
273
|
+
base: config.kit.paths.base,
|
|
274
|
+
assets
|
|
275
|
+
},
|
|
276
|
+
prefix: '',
|
|
277
|
+
prerender: config.kit.prerender.enabled,
|
|
278
|
+
read: (file) => fs__default.readFileSync(path__default.join(config.kit.files.assets, file)),
|
|
279
|
+
root,
|
|
280
|
+
router: config.kit.browser.router,
|
|
281
|
+
template: ({ head, body, assets, nonce }) => {
|
|
282
|
+
return (
|
|
283
|
+
template
|
|
284
|
+
.replace(/%svelte\.assets%/g, assets)
|
|
285
|
+
.replace(/%svelte\.nonce%/g, nonce)
|
|
286
|
+
// head and body must be replaced last, in case someone tries to sneak in %svelte.assets% etc
|
|
287
|
+
.replace('%svelte.head%', () => head)
|
|
288
|
+
.replace('%svelte.body%', () => body)
|
|
289
|
+
);
|
|
290
|
+
},
|
|
291
|
+
template_contains_nonce: template.includes('%svelte.nonce%'),
|
|
292
|
+
trailing_slash: config.kit.trailingSlash
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
if (rendered) {
|
|
296
|
+
setResponse(res, rendered);
|
|
297
|
+
} else {
|
|
298
|
+
not_found(res);
|
|
299
|
+
}
|
|
300
|
+
} catch (e) {
|
|
301
|
+
const error = coalesce_to_error(e);
|
|
302
|
+
vite.ssrFixStacktrace(error);
|
|
303
|
+
res.statusCode = 500;
|
|
304
|
+
res.end(error.stack);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** @param {string[]} array */
|
|
313
|
+
function get_params(array) {
|
|
314
|
+
// given an array of params like `['x', 'y', 'z']` for
|
|
315
|
+
// src/routes/[x]/[y]/[z]/svelte, create a function
|
|
316
|
+
// that turns a RegExpExecArray into ({ x, y, z })
|
|
317
|
+
|
|
318
|
+
/** @param {RegExpExecArray} match */
|
|
319
|
+
const fn = (match) => {
|
|
320
|
+
/** @type {Record<string, string>} */
|
|
321
|
+
const params = {};
|
|
322
|
+
array.forEach((key, i) => {
|
|
323
|
+
if (key.startsWith('...')) {
|
|
324
|
+
params[key.slice(3)] = match[i + 1] || '';
|
|
325
|
+
} else {
|
|
326
|
+
params[key] = match[i + 1];
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
return params;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
return fn;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** @param {import('http').ServerResponse} res */
|
|
336
|
+
function not_found(res) {
|
|
337
|
+
res.statusCode = 404;
|
|
338
|
+
res.end('Not found');
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* @param {import('connect').Server} server
|
|
343
|
+
*/
|
|
344
|
+
function remove_html_middlewares(server) {
|
|
345
|
+
const html_middlewares = [
|
|
346
|
+
'viteIndexHtmlMiddleware',
|
|
347
|
+
'vite404Middleware',
|
|
348
|
+
'viteSpaFallbackMiddleware'
|
|
349
|
+
];
|
|
350
|
+
for (let i = server.stack.length - 1; i > 0; i--) {
|
|
351
|
+
// @ts-expect-error using internals until https://github.com/vitejs/vite/pull/4640 is merged
|
|
352
|
+
if (html_middlewares.includes(server.stack[i].handle.name)) {
|
|
353
|
+
server.stack.splice(i, 1);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* @param {import('vite').ModuleNode} node
|
|
360
|
+
* @param {Set<import('vite').ModuleNode>} deps
|
|
361
|
+
*/
|
|
362
|
+
function find_deps(node, deps) {
|
|
363
|
+
for (const dep of node.importedModules) {
|
|
364
|
+
if (!deps.has(dep)) {
|
|
365
|
+
deps.add(dep);
|
|
366
|
+
find_deps(dep, deps);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* @typedef {{
|
|
373
|
+
* cwd: string,
|
|
374
|
+
* port: number,
|
|
375
|
+
* host?: string,
|
|
376
|
+
* https: boolean,
|
|
377
|
+
* config: import('types/config').ValidatedConfig
|
|
378
|
+
* }} Options
|
|
379
|
+
* @typedef {import('types/internal').SSRComponent} SSRComponent
|
|
380
|
+
*/
|
|
381
|
+
|
|
382
|
+
/** @param {Options} opts */
|
|
383
|
+
async function dev({ cwd, port, host, https, config }) {
|
|
384
|
+
copy_assets(`${SVELTE_KIT}/runtime`);
|
|
385
|
+
|
|
386
|
+
const [vite_config] = deep_merge(
|
|
387
|
+
{
|
|
388
|
+
server: {
|
|
389
|
+
fs: {
|
|
390
|
+
allow: [
|
|
391
|
+
...new Set([
|
|
392
|
+
config.kit.files.assets,
|
|
393
|
+
config.kit.files.lib,
|
|
394
|
+
config.kit.files.routes,
|
|
395
|
+
path__default.resolve(cwd, 'src'),
|
|
396
|
+
path__default.resolve(cwd, SVELTE_KIT),
|
|
397
|
+
path__default.resolve(cwd, 'node_modules'),
|
|
398
|
+
path__default.resolve(vite.searchForWorkspaceRoot(cwd), 'node_modules')
|
|
399
|
+
])
|
|
400
|
+
]
|
|
401
|
+
},
|
|
402
|
+
strictPort: true
|
|
403
|
+
}
|
|
404
|
+
},
|
|
405
|
+
await config.kit.vite()
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
/** @type {[any, string[]]} */
|
|
409
|
+
const [merged_config, conflicts] = deep_merge(vite_config, {
|
|
410
|
+
configFile: false,
|
|
411
|
+
root: cwd,
|
|
412
|
+
resolve: {
|
|
413
|
+
alias: get_aliases(config)
|
|
414
|
+
},
|
|
415
|
+
build: {
|
|
416
|
+
rollupOptions: {
|
|
417
|
+
// Vite dependency crawler needs an explicit JS entry point
|
|
418
|
+
// eventhough server otherwise works without it
|
|
419
|
+
input: `${runtime}/client/start.js`
|
|
420
|
+
}
|
|
421
|
+
},
|
|
422
|
+
plugins: [
|
|
423
|
+
svelte({
|
|
424
|
+
extensions: config.extensions,
|
|
425
|
+
emitCss: !config.kit.amp,
|
|
426
|
+
compilerOptions: {
|
|
427
|
+
hydratable: !!config.kit.browser.hydrate
|
|
428
|
+
}
|
|
429
|
+
}),
|
|
430
|
+
await create_plugin(config, cwd)
|
|
431
|
+
],
|
|
432
|
+
base: '/'
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
print_config_conflicts(conflicts, 'kit.vite.');
|
|
436
|
+
|
|
437
|
+
// optional config from command-line flags
|
|
438
|
+
// these should take precedence, but not print conflict warnings
|
|
439
|
+
if (host) {
|
|
440
|
+
merged_config.server.host = host;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// if https is already enabled then do nothing. it could be an object and we
|
|
444
|
+
// don't want to overwrite with a boolean
|
|
445
|
+
if (https && !merged_config.server.https) {
|
|
446
|
+
merged_config.server.https = https;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
if (port) {
|
|
450
|
+
merged_config.server.port = port;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
const server = await vite.createServer(merged_config);
|
|
454
|
+
await server.listen(port);
|
|
455
|
+
|
|
456
|
+
const address_info = /** @type {import('net').AddressInfo} */ (
|
|
457
|
+
/** @type {import('http').Server} */ (server.httpServer).address()
|
|
458
|
+
);
|
|
459
|
+
|
|
460
|
+
return {
|
|
461
|
+
address_info,
|
|
462
|
+
server_config: vite_config.server,
|
|
463
|
+
close: () => server.close()
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export { dev };
|