@sveltejs/kit 1.0.0-next.580 → 1.0.0-next.582
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.582",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sveltejs/kit",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"marked": "^4.2.3",
|
|
36
36
|
"rollup": "^3.7.0",
|
|
37
37
|
"svelte": "^3.54.0",
|
|
38
|
-
"svelte-preprocess": "^
|
|
38
|
+
"svelte-preprocess": "^5.0.0",
|
|
39
39
|
"typescript": "^4.9.3",
|
|
40
40
|
"uvu": "^0.5.6",
|
|
41
41
|
"vite": "^4.0.0"
|
|
@@ -108,39 +108,22 @@ export function resolve_symlinks(manifest, file) {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
|
-
*
|
|
111
|
+
* Partial Vite configuration that we use by default for setting up the build.
|
|
112
|
+
* Can be used in a non-SvelteKit Vite server and build process such as Storybook.
|
|
112
113
|
* @param {{
|
|
113
114
|
* config: import('types').ValidatedConfig;
|
|
114
|
-
* input: Record<string, string>;
|
|
115
115
|
* ssr: boolean;
|
|
116
|
-
* outDir: string;
|
|
117
116
|
* }} options
|
|
118
117
|
* @return {import('vite').UserConfig}
|
|
119
118
|
*/
|
|
120
|
-
export function
|
|
119
|
+
export function get_build_setup_config({ config, ssr }) {
|
|
121
120
|
const prefix = `${config.kit.appDir}/immutable`;
|
|
122
121
|
|
|
123
122
|
return {
|
|
124
|
-
appType: 'custom',
|
|
125
|
-
base: ssr ? assets_base(config.kit) : './',
|
|
126
123
|
build: {
|
|
127
|
-
cssCodeSplit: true,
|
|
128
124
|
// don't use the default name to avoid collisions with 'static/manifest.json'
|
|
129
125
|
manifest: 'vite-manifest.json',
|
|
130
|
-
|
|
131
|
-
rollupOptions: {
|
|
132
|
-
input,
|
|
133
|
-
output: {
|
|
134
|
-
format: 'esm',
|
|
135
|
-
entryFileNames: ssr ? '[name].js' : `${prefix}/[name]-[hash].js`,
|
|
136
|
-
chunkFileNames: ssr ? 'chunks/[name].js' : `${prefix}/chunks/[name]-[hash].js`,
|
|
137
|
-
assetFileNames: `${prefix}/assets/[name]-[hash][extname]`,
|
|
138
|
-
hoistTransitiveImports: false
|
|
139
|
-
},
|
|
140
|
-
preserveEntrySignatures: 'strict'
|
|
141
|
-
},
|
|
142
|
-
ssr,
|
|
143
|
-
target: ssr ? 'node14.8' : undefined
|
|
126
|
+
ssr
|
|
144
127
|
},
|
|
145
128
|
define: {
|
|
146
129
|
__SVELTEKIT_ADAPTER_NAME__: JSON.stringify(config.kit.adapter?.name),
|
|
@@ -148,7 +131,6 @@ export function get_default_build_config({ config, input, ssr, outDir }) {
|
|
|
148
131
|
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: JSON.stringify(config.kit.version.pollInterval),
|
|
149
132
|
__SVELTEKIT_EMBEDDED__: config.kit.embedded ? 'true' : 'false'
|
|
150
133
|
},
|
|
151
|
-
publicDir: ssr ? false : config.kit.files.assets,
|
|
152
134
|
resolve: {
|
|
153
135
|
alias: [...get_app_aliases(config.kit), ...get_config_aliases(config.kit)]
|
|
154
136
|
},
|
|
@@ -170,6 +152,57 @@ export function get_default_build_config({ config, input, ssr, outDir }) {
|
|
|
170
152
|
};
|
|
171
153
|
}
|
|
172
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Partial Vite configuration that we use by default for setting up the build.
|
|
157
|
+
* Cannot be used in a non-SvelteKit Vite server and build process such as Storybook.
|
|
158
|
+
* @param {{
|
|
159
|
+
* config: import('types').ValidatedConfig;
|
|
160
|
+
* input: Record<string, string>;
|
|
161
|
+
* ssr: boolean;
|
|
162
|
+
* outDir: string;
|
|
163
|
+
* }} options
|
|
164
|
+
* @return {import('vite').UserConfig}
|
|
165
|
+
*/
|
|
166
|
+
export function get_build_compile_config({ config, input, ssr, outDir }) {
|
|
167
|
+
const prefix = `${config.kit.appDir}/immutable`;
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
appType: 'custom',
|
|
171
|
+
base: ssr ? assets_base(config.kit) : './',
|
|
172
|
+
build: {
|
|
173
|
+
cssCodeSplit: true,
|
|
174
|
+
outDir,
|
|
175
|
+
rollupOptions: {
|
|
176
|
+
input,
|
|
177
|
+
output: {
|
|
178
|
+
format: 'esm',
|
|
179
|
+
entryFileNames: ssr ? '[name].js' : `${prefix}/[name]-[hash].js`,
|
|
180
|
+
chunkFileNames: ssr ? 'chunks/[name].js' : `${prefix}/chunks/[name]-[hash].js`,
|
|
181
|
+
assetFileNames: `${prefix}/assets/[name]-[hash][extname]`,
|
|
182
|
+
hoistTransitiveImports: false
|
|
183
|
+
},
|
|
184
|
+
preserveEntrySignatures: 'strict'
|
|
185
|
+
},
|
|
186
|
+
target: ssr ? 'node16.14' : undefined
|
|
187
|
+
},
|
|
188
|
+
publicDir: ssr ? false : config.kit.files.assets
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* The Vite configuration that we use by default for building.
|
|
194
|
+
* @param {{
|
|
195
|
+
* config: import('types').ValidatedConfig;
|
|
196
|
+
* input: Record<string, string>;
|
|
197
|
+
* ssr: boolean;
|
|
198
|
+
* outDir: string;
|
|
199
|
+
* }} options
|
|
200
|
+
* @return {import('vite').UserConfig}
|
|
201
|
+
*/
|
|
202
|
+
export function get_default_build_config(options) {
|
|
203
|
+
return vite.mergeConfig(get_build_setup_config(options), get_build_compile_config(options));
|
|
204
|
+
}
|
|
205
|
+
|
|
173
206
|
/**
|
|
174
207
|
* @param {import('types').ValidatedKitConfig} config
|
|
175
208
|
* @returns {string}
|
|
@@ -11,7 +11,7 @@ import { posixify, resolve_entry, to_fs } from '../../../utils/filesystem.js';
|
|
|
11
11
|
import { load_error_page, load_template } from '../../../core/config/index.js';
|
|
12
12
|
import { SVELTE_KIT_ASSETS } from '../../../constants.js';
|
|
13
13
|
import * as sync from '../../../core/sync/sync.js';
|
|
14
|
-
import { get_mime_lookup,
|
|
14
|
+
import { get_mime_lookup, runtime_prefix } from '../../../core/utils.js';
|
|
15
15
|
import { compact } from '../../../utils/array.js';
|
|
16
16
|
import { not_found } from '../utils.js';
|
|
17
17
|
|
|
@@ -284,11 +284,6 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
284
284
|
}
|
|
285
285
|
});
|
|
286
286
|
|
|
287
|
-
// set `import { version } from '$app/environment'`
|
|
288
|
-
(await vite.ssrLoadModule(`${runtime_prefix}/env.js`)).set_version(
|
|
289
|
-
svelte_config.kit.version.name
|
|
290
|
-
);
|
|
291
|
-
|
|
292
287
|
return () => {
|
|
293
288
|
const serve_static_middleware = vite.middlewares.stack.find(
|
|
294
289
|
(middleware) =>
|
|
@@ -408,13 +403,6 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
408
403
|
`/${posixify(path.relative(cwd, `${svelte_config.kit.outDir}/generated/root.svelte`))}`
|
|
409
404
|
);
|
|
410
405
|
|
|
411
|
-
const paths = await vite.ssrLoadModule(`${runtime_base}/paths.js`);
|
|
412
|
-
|
|
413
|
-
paths.set_paths({
|
|
414
|
-
base: svelte_config.kit.paths.base,
|
|
415
|
-
assets
|
|
416
|
-
});
|
|
417
|
-
|
|
418
406
|
let request;
|
|
419
407
|
|
|
420
408
|
try {
|
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
import { fork } from 'node:child_process';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
5
6
|
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
|
7
|
+
import colors from 'kleur';
|
|
6
8
|
import * as vite from 'vite';
|
|
9
|
+
|
|
7
10
|
import { mkdirp, posixify, resolve_entry, rimraf } from '../../utils/filesystem.js';
|
|
11
|
+
import { SVELTE_KIT_ASSETS } from '../../constants.js';
|
|
12
|
+
import { create_static_module, create_dynamic_module } from '../../core/env.js';
|
|
8
13
|
import * as sync from '../../core/sync/sync.js';
|
|
14
|
+
import { create_assets } from '../../core/sync/create_manifest_data/index.js';
|
|
15
|
+
import { runtime_base, runtime_directory, runtime_prefix, logger } from '../../core/utils.js';
|
|
16
|
+
import { load_config } from '../../core/config/index.js';
|
|
17
|
+
import { generate_manifest } from '../../core/generate_manifest/index.js';
|
|
9
18
|
import { build_server } from './build/build_server.js';
|
|
10
19
|
import { build_service_worker } from './build/build_service_worker.js';
|
|
11
|
-
import {
|
|
20
|
+
import { find_deps, get_build_setup_config, get_build_compile_config } from './build/utils.js';
|
|
12
21
|
import { dev } from './dev/index.js';
|
|
13
|
-
import {
|
|
14
|
-
import { runtime_directory, logger } from '../../core/utils.js';
|
|
15
|
-
import { find_deps, get_default_build_config } from './build/utils.js';
|
|
22
|
+
import { is_illegal, module_guard, normalize_id } from './graph_analysis/index.js';
|
|
16
23
|
import { preview } from './preview/index.js';
|
|
17
24
|
import { get_config_aliases, get_app_aliases, get_env } from './utils.js';
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import { is_illegal, module_guard, normalize_id } from './graph_analysis/index.js';
|
|
21
|
-
import { create_assets } from '../../core/sync/create_manifest_data/index.js';
|
|
25
|
+
|
|
26
|
+
export { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
|
22
27
|
|
|
23
28
|
const cwd = process.cwd();
|
|
24
29
|
|
|
@@ -166,7 +171,7 @@ function kit({ svelte_config }) {
|
|
|
166
171
|
}
|
|
167
172
|
});
|
|
168
173
|
|
|
169
|
-
return
|
|
174
|
+
return get_build_compile_config({
|
|
170
175
|
config: svelte_config,
|
|
171
176
|
input,
|
|
172
177
|
ssr: false,
|
|
@@ -198,8 +203,8 @@ function kit({ svelte_config }) {
|
|
|
198
203
|
check_vite_version();
|
|
199
204
|
|
|
200
205
|
/** @type {import('vite').Plugin} */
|
|
201
|
-
const
|
|
202
|
-
name: 'vite-plugin-sveltekit-
|
|
206
|
+
const plugin_setup = {
|
|
207
|
+
name: 'vite-plugin-sveltekit-setup',
|
|
203
208
|
|
|
204
209
|
/**
|
|
205
210
|
* Build the SvelteKit-provided Vite config to be merged with the user's vite.config.js file.
|
|
@@ -224,7 +229,7 @@ function kit({ svelte_config }) {
|
|
|
224
229
|
if (is_build) {
|
|
225
230
|
manifest_data = (await sync.all(svelte_config, config_env.mode)).manifest_data;
|
|
226
231
|
|
|
227
|
-
const new_config =
|
|
232
|
+
const new_config = get_build_setup_config({ config: svelte_config, ssr: false });
|
|
228
233
|
|
|
229
234
|
const warning = warn_overridden_config(config, new_config);
|
|
230
235
|
if (warning) console.error(warning + '\n');
|
|
@@ -250,20 +255,10 @@ function kit({ svelte_config }) {
|
|
|
250
255
|
// dev and preview config can be shared
|
|
251
256
|
/** @type {import('vite').UserConfig} */
|
|
252
257
|
const result = {
|
|
253
|
-
appType: 'custom',
|
|
254
|
-
base: './',
|
|
255
|
-
build: {
|
|
256
|
-
rollupOptions: {
|
|
257
|
-
// Vite dependency crawler needs an explicit JS entry point
|
|
258
|
-
// eventhough server otherwise works without it
|
|
259
|
-
input: `${runtime_directory}/client/start.js`
|
|
260
|
-
}
|
|
261
|
-
},
|
|
262
258
|
define: {
|
|
263
259
|
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0',
|
|
264
260
|
__SVELTEKIT_EMBEDDED__: svelte_config.kit.embedded ? 'true' : 'false'
|
|
265
261
|
},
|
|
266
|
-
publicDir: svelte_config.kit.files.assets,
|
|
267
262
|
resolve: {
|
|
268
263
|
alias: [...get_app_aliases(svelte_config.kit), ...get_config_aliases(svelte_config.kit)]
|
|
269
264
|
},
|
|
@@ -552,12 +547,68 @@ function kit({ svelte_config }) {
|
|
|
552
547
|
fs.unlinkSync(`${paths.output_dir}/client/${vite_config.build.manifest}`);
|
|
553
548
|
fs.unlinkSync(`${paths.output_dir}/server/${vite_config.build.manifest}`);
|
|
554
549
|
}
|
|
550
|
+
},
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* @see https://vitejs.dev/guide/api-plugin.html#configureserver
|
|
554
|
+
*/
|
|
555
|
+
async configureServer(vite) {
|
|
556
|
+
// set `import { version } from '$app/environment'`
|
|
557
|
+
(await vite.ssrLoadModule(`${runtime_prefix}/env.js`)).set_version(
|
|
558
|
+
svelte_config.kit.version.name
|
|
559
|
+
);
|
|
560
|
+
|
|
561
|
+
// set `import { base, assets } from '$app/paths'`
|
|
562
|
+
const { base, assets } = svelte_config.kit.paths;
|
|
563
|
+
|
|
564
|
+
(await vite.ssrLoadModule(`${runtime_base}/paths.js`)).set_paths({
|
|
565
|
+
base,
|
|
566
|
+
assets: assets ? SVELTE_KIT_ASSETS : base
|
|
567
|
+
});
|
|
555
568
|
}
|
|
556
569
|
};
|
|
557
570
|
|
|
558
571
|
/** @type {import('vite').Plugin} */
|
|
559
|
-
const
|
|
560
|
-
name: 'vite-plugin-sveltekit-
|
|
572
|
+
const plugin_compile = {
|
|
573
|
+
name: 'vite-plugin-sveltekit-compile',
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Build the SvelteKit-provided Vite config to be merged with the user's vite.config.js file.
|
|
577
|
+
* @see https://vitejs.dev/guide/api-plugin.html#config
|
|
578
|
+
*/
|
|
579
|
+
async config(config, config_env) {
|
|
580
|
+
// The config is created in build_server for SSR mode and passed inline
|
|
581
|
+
if (config.build?.ssr) return;
|
|
582
|
+
|
|
583
|
+
if (config_env.command === 'build') {
|
|
584
|
+
const new_config = vite_client_build_config();
|
|
585
|
+
|
|
586
|
+
const warning = warn_overridden_config(config, new_config);
|
|
587
|
+
if (warning) console.error(warning + '\n');
|
|
588
|
+
|
|
589
|
+
return new_config;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// dev and preview config can be shared
|
|
593
|
+
/** @type {import('vite').UserConfig} */
|
|
594
|
+
const result = {
|
|
595
|
+
appType: 'custom',
|
|
596
|
+
base: svelte_config.kit.paths.base,
|
|
597
|
+
build: {
|
|
598
|
+
rollupOptions: {
|
|
599
|
+
// Vite dependency crawler needs an explicit JS entry point
|
|
600
|
+
// eventhough server otherwise works without it
|
|
601
|
+
input: `${runtime_directory}/client/start.js`
|
|
602
|
+
}
|
|
603
|
+
},
|
|
604
|
+
publicDir: svelte_config.kit.files.assets
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
const warning = warn_overridden_config(config, result);
|
|
608
|
+
if (warning) console.error(warning);
|
|
609
|
+
|
|
610
|
+
return result;
|
|
611
|
+
},
|
|
561
612
|
|
|
562
613
|
/**
|
|
563
614
|
* Adds the SvelteKit middleware to do SSR in dev mode.
|
|
@@ -576,7 +627,7 @@ function kit({ svelte_config }) {
|
|
|
576
627
|
}
|
|
577
628
|
};
|
|
578
629
|
|
|
579
|
-
return [
|
|
630
|
+
return [plugin_setup, plugin_compile];
|
|
580
631
|
}
|
|
581
632
|
|
|
582
633
|
function check_vite_version() {
|
|
@@ -632,8 +683,12 @@ function warn_overridden_config(config, resolved_config) {
|
|
|
632
683
|
* @param {string[]} out used locally to compute the return value
|
|
633
684
|
*/
|
|
634
685
|
function find_overridden_config(config, resolved_config, enforced_config, path, out) {
|
|
686
|
+
if (config == null || resolved_config == null) {
|
|
687
|
+
return out;
|
|
688
|
+
}
|
|
689
|
+
|
|
635
690
|
for (const key in enforced_config) {
|
|
636
|
-
if (typeof config === 'object' &&
|
|
691
|
+
if (typeof config === 'object' && key in config && key in resolved_config) {
|
|
637
692
|
const enforced = enforced_config[key];
|
|
638
693
|
|
|
639
694
|
if (enforced === true) {
|
|
@@ -645,7 +700,6 @@ function find_overridden_config(config, resolved_config, enforced_config, path,
|
|
|
645
700
|
}
|
|
646
701
|
}
|
|
647
702
|
}
|
|
648
|
-
|
|
649
703
|
return out;
|
|
650
704
|
}
|
|
651
705
|
|
|
@@ -173,8 +173,12 @@ export function not_found(req, res, base) {
|
|
|
173
173
|
|
|
174
174
|
if (type === 'text/html') {
|
|
175
175
|
res.setHeader('Content-Type', 'text/html');
|
|
176
|
-
res.end(
|
|
176
|
+
res.end(
|
|
177
|
+
`The server is configured with a public base URL of /path-base - did you mean to visit <a href="${prefixed}">${prefixed}</a> instead?`
|
|
178
|
+
);
|
|
177
179
|
} else {
|
|
178
|
-
res.end(
|
|
180
|
+
res.end(
|
|
181
|
+
`The server is configured with a public base URL of /path-base - did you mean to visit ${prefixed} instead?`
|
|
182
|
+
);
|
|
179
183
|
}
|
|
180
184
|
}
|