@sveltejs/kit 1.1.2 → 1.1.4
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 +1 -1
- package/src/exports/vite/build/build_server.js +17 -52
- package/src/exports/vite/build/utils.js +2 -135
- package/src/exports/vite/dev/index.js +5 -4
- package/src/exports/vite/index.js +252 -222
- package/src/exports/vite/utils.js +1 -88
- package/src/runtime/client/client.js +10 -5
- package/src/runtime/client/utils.js +7 -7
- package/types/ambient.d.ts +7 -3
package/package.json
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import * as vite from 'vite';
|
|
4
4
|
import { mkdirp, posixify } from '../../../utils/filesystem.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
create_build,
|
|
8
|
-
find_deps,
|
|
9
|
-
get_default_build_config,
|
|
10
|
-
is_http_method,
|
|
11
|
-
resolve_symlinks
|
|
12
|
-
} from './utils.js';
|
|
5
|
+
import { find_deps, is_http_method, resolve_symlinks } from './utils.js';
|
|
13
6
|
import { s } from '../../../utils/misc.js';
|
|
14
|
-
import { runtime_directory } from '../../../core/utils.js';
|
|
15
7
|
|
|
16
8
|
/**
|
|
17
9
|
* @param {{
|
|
@@ -26,49 +18,22 @@ import { runtime_directory } from '../../../core/utils.js';
|
|
|
26
18
|
export async function build_server(options, client) {
|
|
27
19
|
const { config, vite_config, vite_config_env, manifest_data, output_dir } = options;
|
|
28
20
|
|
|
29
|
-
/** @type {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const resolved = path.resolve(route.endpoint.file);
|
|
39
|
-
const relative = decodeURIComponent(path.relative(config.kit.files.routes, resolved));
|
|
40
|
-
const name = posixify(path.join('entries/endpoints', relative.replace(/\.js$/, '')));
|
|
41
|
-
input[name] = resolved;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// ...and every component used by pages...
|
|
46
|
-
manifest_data.nodes.forEach((node) => {
|
|
47
|
-
for (const file of [node.component, node.universal, node.server]) {
|
|
48
|
-
if (file) {
|
|
49
|
-
const resolved = path.resolve(file);
|
|
50
|
-
const relative = decodeURIComponent(path.relative(config.kit.files.routes, resolved));
|
|
51
|
-
|
|
52
|
-
const name = relative.startsWith('..')
|
|
53
|
-
? posixify(path.join('entries/fallbacks', path.basename(file)))
|
|
54
|
-
: posixify(path.join('entries/pages', relative.replace(/\.js$/, '')));
|
|
55
|
-
input[name] = resolved;
|
|
21
|
+
const { output } = /** @type {import('rollup').RollupOutput} */ (
|
|
22
|
+
await vite.build({
|
|
23
|
+
// CLI args
|
|
24
|
+
configFile: vite_config.configFile,
|
|
25
|
+
mode: vite_config_env.mode,
|
|
26
|
+
logLevel: config.logLevel,
|
|
27
|
+
clearScreen: config.clearScreen,
|
|
28
|
+
build: {
|
|
29
|
+
ssr: true
|
|
56
30
|
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// ...and every matcher
|
|
61
|
-
Object.entries(manifest_data.matchers).forEach(([key, file]) => {
|
|
62
|
-
const name = posixify(path.join('entries/matchers', key));
|
|
63
|
-
input[name] = path.resolve(file);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const merged_config = mergeConfig(
|
|
67
|
-
get_default_build_config({ config, input, ssr: true, outDir: `${output_dir}/server` }),
|
|
68
|
-
await get_vite_config(vite_config, vite_config_env)
|
|
31
|
+
})
|
|
69
32
|
);
|
|
70
33
|
|
|
71
|
-
const
|
|
34
|
+
const chunks = /** @type {import('rollup').OutputChunk[]} */ (
|
|
35
|
+
output.filter((chunk) => chunk.type === 'chunk')
|
|
36
|
+
);
|
|
72
37
|
|
|
73
38
|
/** @type {import('vite').Manifest} */
|
|
74
39
|
const vite_manifest = JSON.parse(
|
|
@@ -1,33 +1,5 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import * as vite from 'vite';
|
|
4
|
-
import { get_config_aliases, get_app_aliases } from '../utils.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @typedef {import('rollup').RollupOutput} RollupOutput
|
|
8
|
-
* @typedef {import('rollup').OutputChunk} OutputChunk
|
|
9
|
-
* @typedef {import('rollup').OutputAsset} OutputAsset
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Invokes Vite.
|
|
14
|
-
* @param {import('vite').UserConfig} config
|
|
15
|
-
*/
|
|
16
|
-
export async function create_build(config) {
|
|
17
|
-
const { output } = /** @type {RollupOutput} */ (
|
|
18
|
-
await vite.build({ ...config, configFile: false })
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
const chunks = output.filter(
|
|
22
|
-
/** @returns {output is OutputChunk} */ (output) => output.type === 'chunk'
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
const assets = output.filter(
|
|
26
|
-
/** @returns {output is OutputAsset} */ (output) => output.type === 'asset'
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
return { chunks, assets };
|
|
30
|
-
}
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
31
3
|
|
|
32
4
|
/**
|
|
33
5
|
* Adds transitive JS and CSS dependencies to the js and css inputs.
|
|
@@ -107,111 +79,6 @@ export function resolve_symlinks(manifest, file) {
|
|
|
107
79
|
return { chunk, file };
|
|
108
80
|
}
|
|
109
81
|
|
|
110
|
-
/**
|
|
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.
|
|
113
|
-
* @param {{
|
|
114
|
-
* config: import('types').ValidatedConfig;
|
|
115
|
-
* ssr: boolean;
|
|
116
|
-
* }} options
|
|
117
|
-
* @return {import('vite').UserConfig}
|
|
118
|
-
*/
|
|
119
|
-
export function get_build_setup_config({ config, ssr }) {
|
|
120
|
-
return {
|
|
121
|
-
build: {
|
|
122
|
-
// don't use the default name to avoid collisions with 'static/manifest.json'
|
|
123
|
-
manifest: 'vite-manifest.json',
|
|
124
|
-
ssr
|
|
125
|
-
},
|
|
126
|
-
define: {
|
|
127
|
-
__SVELTEKIT_ADAPTER_NAME__: JSON.stringify(config.kit.adapter?.name),
|
|
128
|
-
__SVELTEKIT_APP_VERSION_FILE__: JSON.stringify(`${config.kit.appDir}/version.json`),
|
|
129
|
-
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: JSON.stringify(config.kit.version.pollInterval),
|
|
130
|
-
__SVELTEKIT_DEV__: 'false',
|
|
131
|
-
__SVELTEKIT_EMBEDDED__: config.kit.embedded ? 'true' : 'false'
|
|
132
|
-
},
|
|
133
|
-
resolve: {
|
|
134
|
-
alias: [...get_app_aliases(config.kit), ...get_config_aliases(config.kit)]
|
|
135
|
-
},
|
|
136
|
-
optimizeDeps: {
|
|
137
|
-
exclude: ['@sveltejs/kit']
|
|
138
|
-
},
|
|
139
|
-
ssr: {
|
|
140
|
-
noExternal: [
|
|
141
|
-
// TODO document why this is necessary
|
|
142
|
-
'@sveltejs/kit',
|
|
143
|
-
// This ensures that esm-env is inlined into the server output with the
|
|
144
|
-
// export conditions resolved correctly through Vite. This prevents adapters
|
|
145
|
-
// that bundle later on to resolve the export conditions incorrectly
|
|
146
|
-
// and for example include browser-only code in the server output
|
|
147
|
-
// because they for example use esbuild.build with `platform: 'browser'`
|
|
148
|
-
'esm-env'
|
|
149
|
-
]
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Partial Vite configuration that we use by default for setting up the build.
|
|
156
|
-
* Cannot be used in a non-SvelteKit Vite server and build process such as Storybook.
|
|
157
|
-
* @param {{
|
|
158
|
-
* config: import('types').ValidatedConfig;
|
|
159
|
-
* input: Record<string, string>;
|
|
160
|
-
* ssr: boolean;
|
|
161
|
-
* outDir: string;
|
|
162
|
-
* }} options
|
|
163
|
-
* @return {import('vite').UserConfig}
|
|
164
|
-
*/
|
|
165
|
-
export function get_build_compile_config({ config, input, ssr, outDir }) {
|
|
166
|
-
const prefix = `${config.kit.appDir}/immutable`;
|
|
167
|
-
|
|
168
|
-
return {
|
|
169
|
-
appType: 'custom',
|
|
170
|
-
base: ssr ? assets_base(config.kit) : './',
|
|
171
|
-
build: {
|
|
172
|
-
cssCodeSplit: true,
|
|
173
|
-
outDir,
|
|
174
|
-
rollupOptions: {
|
|
175
|
-
input,
|
|
176
|
-
output: {
|
|
177
|
-
format: 'esm',
|
|
178
|
-
entryFileNames: ssr ? '[name].js' : `${prefix}/[name]-[hash].js`,
|
|
179
|
-
chunkFileNames: ssr ? 'chunks/[name].js' : `${prefix}/chunks/[name]-[hash].js`,
|
|
180
|
-
assetFileNames: `${prefix}/assets/[name]-[hash][extname]`,
|
|
181
|
-
hoistTransitiveImports: false
|
|
182
|
-
},
|
|
183
|
-
preserveEntrySignatures: 'strict'
|
|
184
|
-
},
|
|
185
|
-
target: ssr ? 'node16.14' : undefined
|
|
186
|
-
},
|
|
187
|
-
publicDir: ssr ? false : config.kit.files.assets,
|
|
188
|
-
worker: {
|
|
189
|
-
rollupOptions: {
|
|
190
|
-
output: {
|
|
191
|
-
entryFileNames: `${prefix}/workers/[name]-[hash].js`,
|
|
192
|
-
chunkFileNames: `${prefix}/workers/chunks/[name]-[hash].js`,
|
|
193
|
-
assetFileNames: `${prefix}/workers/assets/[name]-[hash][extname]`,
|
|
194
|
-
hoistTransitiveImports: false
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* The Vite configuration that we use by default for building.
|
|
203
|
-
* @param {{
|
|
204
|
-
* config: import('types').ValidatedConfig;
|
|
205
|
-
* input: Record<string, string>;
|
|
206
|
-
* ssr: boolean;
|
|
207
|
-
* outDir: string;
|
|
208
|
-
* }} options
|
|
209
|
-
* @return {import('vite').UserConfig}
|
|
210
|
-
*/
|
|
211
|
-
export function get_default_build_config(options) {
|
|
212
|
-
return vite.mergeConfig(get_build_setup_config(options), get_build_compile_config(options));
|
|
213
|
-
}
|
|
214
|
-
|
|
215
82
|
/**
|
|
216
83
|
* @param {import('types').ValidatedKitConfig} config
|
|
217
84
|
* @returns {string}
|
|
@@ -408,15 +408,16 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
408
408
|
return;
|
|
409
409
|
}
|
|
410
410
|
|
|
411
|
+
// we have to import `Server` before calling `set_paths`
|
|
412
|
+
const { Server } = /** @type {import('types').ServerModule} */ (
|
|
413
|
+
await vite.ssrLoadModule(`${runtime_base}/server/index.js`)
|
|
414
|
+
);
|
|
415
|
+
|
|
411
416
|
const { set_paths, set_version, set_fix_stack_trace } =
|
|
412
417
|
/** @type {import('types').ServerInternalModule} */ (
|
|
413
418
|
await vite.ssrLoadModule(`${runtime_base}/shared.js`)
|
|
414
419
|
);
|
|
415
420
|
|
|
416
|
-
const { Server } = /** @type {import('types').ServerModule} */ (
|
|
417
|
-
await vite.ssrLoadModule(`${runtime_base}/server/index.js`)
|
|
418
|
-
);
|
|
419
|
-
|
|
420
421
|
set_paths({
|
|
421
422
|
base: svelte_config.kit.paths.base,
|
|
422
423
|
assets
|
|
@@ -8,20 +8,19 @@ import colors from 'kleur';
|
|
|
8
8
|
import * as vite from 'vite';
|
|
9
9
|
|
|
10
10
|
import { mkdirp, posixify, resolve_entry, rimraf } from '../../utils/filesystem.js';
|
|
11
|
-
import { SVELTE_KIT_ASSETS } from '../../constants.js';
|
|
12
11
|
import { create_static_module, create_dynamic_module } from '../../core/env.js';
|
|
13
12
|
import * as sync from '../../core/sync/sync.js';
|
|
14
13
|
import { create_assets } from '../../core/sync/create_manifest_data/index.js';
|
|
15
|
-
import {
|
|
14
|
+
import { runtime_directory, logger } from '../../core/utils.js';
|
|
16
15
|
import { load_config } from '../../core/config/index.js';
|
|
17
16
|
import { generate_manifest } from '../../core/generate_manifest/index.js';
|
|
18
17
|
import { build_server } from './build/build_server.js';
|
|
19
18
|
import { build_service_worker } from './build/build_service_worker.js';
|
|
20
|
-
import {
|
|
19
|
+
import { assets_base, find_deps } from './build/utils.js';
|
|
21
20
|
import { dev } from './dev/index.js';
|
|
22
21
|
import { is_illegal, module_guard, normalize_id } from './graph_analysis/index.js';
|
|
23
22
|
import { preview } from './preview/index.js';
|
|
24
|
-
import { get_config_aliases,
|
|
23
|
+
import { get_config_aliases, get_env } from './utils.js';
|
|
25
24
|
|
|
26
25
|
export { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
|
27
26
|
|
|
@@ -153,6 +152,9 @@ export async function sveltekit() {
|
|
|
153
152
|
* @return {import('vite').Plugin[]}
|
|
154
153
|
*/
|
|
155
154
|
function kit({ svelte_config }) {
|
|
155
|
+
const { kit } = svelte_config;
|
|
156
|
+
const out = `${kit.outDir}/output`;
|
|
157
|
+
|
|
156
158
|
/** @type {import('vite').ResolvedConfig} */
|
|
157
159
|
let vite_config;
|
|
158
160
|
|
|
@@ -180,78 +182,8 @@ function kit({ svelte_config }) {
|
|
|
180
182
|
/** @type {{ public: Record<string, string>; private: Record<string, string> }} */
|
|
181
183
|
let env;
|
|
182
184
|
|
|
183
|
-
/**
|
|
184
|
-
* @type {{
|
|
185
|
-
* output_dir: string;
|
|
186
|
-
* client_out_dir: string;
|
|
187
|
-
* }}
|
|
188
|
-
*/
|
|
189
|
-
let paths;
|
|
190
|
-
|
|
191
185
|
let completed_build = false;
|
|
192
186
|
|
|
193
|
-
function vite_client_build_config() {
|
|
194
|
-
/** @type {Record<string, string>} */
|
|
195
|
-
const input = {
|
|
196
|
-
// Put unchanging assets in immutable directory. We don't set that in the
|
|
197
|
-
// outDir so that other plugins can add mutable assets to the bundle
|
|
198
|
-
start: `${runtime_directory}/client/start.js`
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
manifest_data.nodes.forEach((node) => {
|
|
202
|
-
if (node.component) {
|
|
203
|
-
const resolved = path.resolve(node.component);
|
|
204
|
-
const relative = decodeURIComponent(
|
|
205
|
-
path.relative(svelte_config.kit.files.routes, resolved)
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
const name = relative.startsWith('..')
|
|
209
|
-
? path.basename(node.component)
|
|
210
|
-
: posixify(path.join('pages', relative));
|
|
211
|
-
input[`components/${name}`] = resolved;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (node.universal) {
|
|
215
|
-
const resolved = path.resolve(node.universal);
|
|
216
|
-
const relative = decodeURIComponent(
|
|
217
|
-
path.relative(svelte_config.kit.files.routes, resolved)
|
|
218
|
-
);
|
|
219
|
-
|
|
220
|
-
const name = relative.startsWith('..')
|
|
221
|
-
? path.basename(node.universal)
|
|
222
|
-
: posixify(path.join('pages', relative));
|
|
223
|
-
input[`modules/${name}`] = resolved;
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
return get_build_compile_config({
|
|
228
|
-
config: svelte_config,
|
|
229
|
-
input,
|
|
230
|
-
ssr: false,
|
|
231
|
-
outDir: `${paths.client_out_dir}`
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* @param {import('rollup').OutputAsset[]} assets
|
|
237
|
-
* @param {import('rollup').OutputChunk[]} chunks
|
|
238
|
-
*/
|
|
239
|
-
function client_build_info(assets, chunks) {
|
|
240
|
-
/** @type {import('vite').Manifest} */
|
|
241
|
-
const vite_manifest = JSON.parse(
|
|
242
|
-
fs.readFileSync(`${paths.client_out_dir}/${vite_config.build.manifest}`, 'utf-8')
|
|
243
|
-
);
|
|
244
|
-
|
|
245
|
-
const entry_id = posixify(path.relative('.', `${runtime_directory}/client/start.js`));
|
|
246
|
-
|
|
247
|
-
return {
|
|
248
|
-
assets,
|
|
249
|
-
chunks,
|
|
250
|
-
entry: find_deps(vite_manifest, entry_id, false),
|
|
251
|
-
vite_manifest
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
|
|
255
187
|
/** @type {import('vite').Plugin} */
|
|
256
188
|
const plugin_setup = {
|
|
257
189
|
name: 'vite-plugin-sveltekit-setup',
|
|
@@ -262,55 +194,33 @@ function kit({ svelte_config }) {
|
|
|
262
194
|
*/
|
|
263
195
|
async config(config, config_env) {
|
|
264
196
|
vite_config_env = config_env;
|
|
265
|
-
|
|
266
|
-
env = get_env(svelte_config.kit.env, vite_config_env.mode);
|
|
267
|
-
|
|
268
|
-
// The config is created in build_server for SSR mode and passed inline
|
|
269
|
-
if (config.build?.ssr) return;
|
|
270
|
-
|
|
271
197
|
is_build = config_env.command === 'build';
|
|
272
198
|
|
|
273
|
-
|
|
274
|
-
output_dir: `${svelte_config.kit.outDir}/output`,
|
|
275
|
-
client_out_dir: `${svelte_config.kit.outDir}/output/client`
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
if (is_build) {
|
|
279
|
-
manifest_data = (await sync.all(svelte_config, config_env.mode)).manifest_data;
|
|
280
|
-
|
|
281
|
-
const new_config = get_build_setup_config({ config: svelte_config, ssr: false });
|
|
282
|
-
|
|
283
|
-
const warning = warn_overridden_config(config, new_config);
|
|
284
|
-
if (warning) console.error(warning + '\n');
|
|
285
|
-
|
|
286
|
-
return new_config;
|
|
287
|
-
}
|
|
199
|
+
env = get_env(kit.env, vite_config_env.mode);
|
|
288
200
|
|
|
289
201
|
const allow = new Set([
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
202
|
+
kit.files.lib,
|
|
203
|
+
kit.files.routes,
|
|
204
|
+
kit.outDir,
|
|
293
205
|
path.resolve('src'), // TODO this isn't correct if user changed all his files to sth else than src (like in test/options)
|
|
294
206
|
path.resolve('node_modules'),
|
|
295
207
|
path.resolve(vite.searchForWorkspaceRoot(cwd), 'node_modules')
|
|
296
208
|
]);
|
|
209
|
+
|
|
297
210
|
// We can only add directories to the allow list, so we find out
|
|
298
211
|
// if there's a client hooks file and pass its directory
|
|
299
|
-
const client_hooks = resolve_entry(
|
|
300
|
-
if (client_hooks)
|
|
301
|
-
allow.add(path.dirname(client_hooks));
|
|
302
|
-
}
|
|
212
|
+
const client_hooks = resolve_entry(kit.files.hooks.client);
|
|
213
|
+
if (client_hooks) allow.add(path.dirname(client_hooks));
|
|
303
214
|
|
|
304
215
|
// dev and preview config can be shared
|
|
305
216
|
/** @type {import('vite').UserConfig} */
|
|
306
|
-
const
|
|
307
|
-
define: {
|
|
308
|
-
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0',
|
|
309
|
-
__SVELTEKIT_DEV__: config_env.command === 'serve',
|
|
310
|
-
__SVELTEKIT_EMBEDDED__: svelte_config.kit.embedded ? 'true' : 'false'
|
|
311
|
-
},
|
|
217
|
+
const new_config = {
|
|
312
218
|
resolve: {
|
|
313
|
-
alias: [
|
|
219
|
+
alias: [
|
|
220
|
+
{ find: '__GENERATED__', replacement: path.posix.join(kit.outDir, 'generated') },
|
|
221
|
+
{ find: '$app', replacement: `${runtime_directory}/app` },
|
|
222
|
+
...get_config_aliases(kit)
|
|
223
|
+
]
|
|
314
224
|
},
|
|
315
225
|
root: cwd,
|
|
316
226
|
server: {
|
|
@@ -320,17 +230,10 @@ function kit({ svelte_config }) {
|
|
|
320
230
|
watch: {
|
|
321
231
|
ignored: [
|
|
322
232
|
// Ignore all siblings of config.kit.outDir/generated
|
|
323
|
-
`${posixify(
|
|
233
|
+
`${posixify(kit.outDir)}/!(generated)`
|
|
324
234
|
]
|
|
325
235
|
}
|
|
326
236
|
},
|
|
327
|
-
ssr: {
|
|
328
|
-
// Without this, Vite will treat `@sveltejs/kit` as noExternal if it's
|
|
329
|
-
// a linked dependency, and that causes modules to be imported twice
|
|
330
|
-
// under different IDs, which breaks a bunch of stuff
|
|
331
|
-
// https://github.com/vitejs/vite/pull/9296
|
|
332
|
-
external: ['@sveltejs/kit', 'cookie', 'set-cookie-parser']
|
|
333
|
-
},
|
|
334
237
|
optimizeDeps: {
|
|
335
238
|
exclude: [
|
|
336
239
|
'@sveltejs/kit',
|
|
@@ -342,12 +245,64 @@ function kit({ svelte_config }) {
|
|
|
342
245
|
}
|
|
343
246
|
};
|
|
344
247
|
|
|
345
|
-
|
|
346
|
-
|
|
248
|
+
if (is_build) {
|
|
249
|
+
new_config.define = {
|
|
250
|
+
__SVELTEKIT_ADAPTER_NAME__: JSON.stringify(kit.adapter?.name),
|
|
251
|
+
__SVELTEKIT_APP_VERSION_FILE__: JSON.stringify(`${kit.appDir}/version.json`),
|
|
252
|
+
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: JSON.stringify(kit.version.pollInterval),
|
|
253
|
+
__SVELTEKIT_DEV__: 'false',
|
|
254
|
+
__SVELTEKIT_EMBEDDED__: kit.embedded ? 'true' : 'false'
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
new_config.ssr = {
|
|
258
|
+
noExternal: [
|
|
259
|
+
// TODO document why this is necessary
|
|
260
|
+
'@sveltejs/kit',
|
|
261
|
+
// This ensures that esm-env is inlined into the server output with the
|
|
262
|
+
// export conditions resolved correctly through Vite. This prevents adapters
|
|
263
|
+
// that bundle later on to resolve the export conditions incorrectly
|
|
264
|
+
// and for example include browser-only code in the server output
|
|
265
|
+
// because they for example use esbuild.build with `platform: 'browser'`
|
|
266
|
+
'esm-env'
|
|
267
|
+
]
|
|
268
|
+
};
|
|
269
|
+
} else {
|
|
270
|
+
new_config.define = {
|
|
271
|
+
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0',
|
|
272
|
+
__SVELTEKIT_DEV__: 'true',
|
|
273
|
+
__SVELTEKIT_EMBEDDED__: kit.embedded ? 'true' : 'false'
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
new_config.ssr = {
|
|
277
|
+
// Without this, Vite will treat `@sveltejs/kit` as noExternal if it's
|
|
278
|
+
// a linked dependency, and that causes modules to be imported twice
|
|
279
|
+
// under different IDs, which breaks a bunch of stuff
|
|
280
|
+
// https://github.com/vitejs/vite/pull/9296
|
|
281
|
+
external: ['@sveltejs/kit', 'cookie', 'set-cookie-parser']
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
warn_overridden_config(config, new_config);
|
|
347
286
|
|
|
348
|
-
return
|
|
287
|
+
return new_config;
|
|
349
288
|
},
|
|
350
289
|
|
|
290
|
+
/**
|
|
291
|
+
* Stores the final config.
|
|
292
|
+
*/
|
|
293
|
+
configResolved(config) {
|
|
294
|
+
vite_config = config;
|
|
295
|
+
|
|
296
|
+
// This is a hack to prevent Vite from nuking useful logs,
|
|
297
|
+
// pending https://github.com/vitejs/vite/issues/9378
|
|
298
|
+
config.logger.warn('');
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
/** @type {import('vite').Plugin} */
|
|
303
|
+
const plugin_virtual_modules = {
|
|
304
|
+
name: 'vite-plugin-sveltekit-virtual-modules',
|
|
305
|
+
|
|
351
306
|
async resolveId(id) {
|
|
352
307
|
// treat $env/static/[public|private] as virtual
|
|
353
308
|
if (id.startsWith('$env/') || id === '$service-worker') return `\0${id}`;
|
|
@@ -356,7 +311,7 @@ function kit({ svelte_config }) {
|
|
|
356
311
|
async load(id, options) {
|
|
357
312
|
if (options?.ssr === false && process.env.TEST !== 'true') {
|
|
358
313
|
const normalized_cwd = vite.normalizePath(cwd);
|
|
359
|
-
const normalized_lib = vite.normalizePath(
|
|
314
|
+
const normalized_lib = vite.normalizePath(kit.files.lib);
|
|
360
315
|
if (
|
|
361
316
|
is_illegal(id, {
|
|
362
317
|
cwd: normalized_cwd,
|
|
@@ -387,62 +342,6 @@ function kit({ svelte_config }) {
|
|
|
387
342
|
case '\0$service-worker':
|
|
388
343
|
return create_service_worker_module(svelte_config);
|
|
389
344
|
}
|
|
390
|
-
},
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Stores the final config.
|
|
394
|
-
*/
|
|
395
|
-
configResolved(config) {
|
|
396
|
-
vite_config = config;
|
|
397
|
-
|
|
398
|
-
// This is a hack to prevent Vite from nuking useful logs,
|
|
399
|
-
// pending https://github.com/vitejs/vite/issues/9378
|
|
400
|
-
config.logger.warn('');
|
|
401
|
-
},
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* Clears the output directories.
|
|
405
|
-
*/
|
|
406
|
-
buildStart() {
|
|
407
|
-
if (vite_config.build.ssr) return;
|
|
408
|
-
|
|
409
|
-
// Reset for new build. Goes here because `build --watch` calls buildStart but not config
|
|
410
|
-
completed_build = false;
|
|
411
|
-
|
|
412
|
-
if (is_build) {
|
|
413
|
-
if (!vite_config.build.watch) {
|
|
414
|
-
rimraf(paths.output_dir);
|
|
415
|
-
}
|
|
416
|
-
mkdirp(paths.output_dir);
|
|
417
|
-
}
|
|
418
|
-
},
|
|
419
|
-
|
|
420
|
-
generateBundle() {
|
|
421
|
-
if (vite_config.build.ssr) return;
|
|
422
|
-
|
|
423
|
-
this.emitFile({
|
|
424
|
-
type: 'asset',
|
|
425
|
-
fileName: `${svelte_config.kit.appDir}/version.json`,
|
|
426
|
-
source: JSON.stringify({ version: svelte_config.kit.version.name })
|
|
427
|
-
});
|
|
428
|
-
},
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* @see https://vitejs.dev/guide/api-plugin.html#configureserver
|
|
432
|
-
*/
|
|
433
|
-
async configureServer(vite) {
|
|
434
|
-
const { set_paths, set_version } = await vite.ssrLoadModule(`${runtime_base}/shared.js`);
|
|
435
|
-
|
|
436
|
-
// set `import { base, assets } from '$app/paths'`
|
|
437
|
-
const { base, assets } = svelte_config.kit.paths;
|
|
438
|
-
|
|
439
|
-
set_paths({
|
|
440
|
-
base,
|
|
441
|
-
assets: assets ? SVELTE_KIT_ASSETS : base
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
// set `import { version } from '$app/environment'`
|
|
445
|
-
set_version(svelte_config.kit.version.name);
|
|
446
345
|
}
|
|
447
346
|
};
|
|
448
347
|
|
|
@@ -455,37 +354,129 @@ function kit({ svelte_config }) {
|
|
|
455
354
|
* @see https://vitejs.dev/guide/api-plugin.html#config
|
|
456
355
|
*/
|
|
457
356
|
async config(config, config_env) {
|
|
458
|
-
|
|
459
|
-
|
|
357
|
+
/** @type {import('vite').UserConfig} */
|
|
358
|
+
let new_config;
|
|
460
359
|
|
|
461
|
-
if (
|
|
462
|
-
|
|
360
|
+
if (is_build) {
|
|
361
|
+
manifest_data = (await sync.all(svelte_config, config_env.mode)).manifest_data;
|
|
463
362
|
|
|
464
|
-
const
|
|
465
|
-
|
|
363
|
+
const ssr = config.build?.ssr ?? false;
|
|
364
|
+
const prefix = `${kit.appDir}/immutable`;
|
|
466
365
|
|
|
467
|
-
|
|
468
|
-
|
|
366
|
+
/** @type {Record<string, string>} */
|
|
367
|
+
const input = {};
|
|
469
368
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
369
|
+
if (ssr) {
|
|
370
|
+
input.index = `${runtime_directory}/server/index.js`;
|
|
371
|
+
input.internal = `${kit.outDir}/generated/server-internal.js`;
|
|
372
|
+
|
|
373
|
+
// add entry points for every endpoint...
|
|
374
|
+
manifest_data.routes.forEach((route) => {
|
|
375
|
+
if (route.endpoint) {
|
|
376
|
+
const resolved = path.resolve(route.endpoint.file);
|
|
377
|
+
const relative = decodeURIComponent(path.relative(kit.files.routes, resolved));
|
|
378
|
+
const name = posixify(path.join('entries/endpoints', relative.replace(/\.js$/, '')));
|
|
379
|
+
input[name] = resolved;
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// ...and every component used by pages...
|
|
384
|
+
manifest_data.nodes.forEach((node) => {
|
|
385
|
+
for (const file of [node.component, node.universal, node.server]) {
|
|
386
|
+
if (file) {
|
|
387
|
+
const resolved = path.resolve(file);
|
|
388
|
+
const relative = decodeURIComponent(path.relative(kit.files.routes, resolved));
|
|
389
|
+
|
|
390
|
+
const name = relative.startsWith('..')
|
|
391
|
+
? posixify(path.join('entries/fallbacks', path.basename(file)))
|
|
392
|
+
: posixify(path.join('entries/pages', relative.replace(/\.js$/, '')));
|
|
393
|
+
input[name] = resolved;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
// ...and every matcher
|
|
399
|
+
Object.entries(manifest_data.matchers).forEach(([key, file]) => {
|
|
400
|
+
const name = posixify(path.join('entries/matchers', key));
|
|
401
|
+
input[name] = path.resolve(file);
|
|
402
|
+
});
|
|
403
|
+
} else {
|
|
404
|
+
/** @type {Record<string, string>} */
|
|
405
|
+
input.start = `${runtime_directory}/client/start.js`;
|
|
406
|
+
|
|
407
|
+
manifest_data.nodes.forEach((node) => {
|
|
408
|
+
if (node.component) {
|
|
409
|
+
const resolved = path.resolve(node.component);
|
|
410
|
+
const relative = decodeURIComponent(path.relative(kit.files.routes, resolved));
|
|
411
|
+
|
|
412
|
+
const name = relative.startsWith('..')
|
|
413
|
+
? path.basename(node.component)
|
|
414
|
+
: posixify(path.join('pages', relative));
|
|
415
|
+
input[`components/${name}`] = resolved;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (node.universal) {
|
|
419
|
+
const resolved = path.resolve(node.universal);
|
|
420
|
+
const relative = decodeURIComponent(path.relative(kit.files.routes, resolved));
|
|
421
|
+
|
|
422
|
+
const name = relative.startsWith('..')
|
|
423
|
+
? path.basename(node.universal)
|
|
424
|
+
: posixify(path.join('pages', relative));
|
|
425
|
+
input[`modules/${name}`] = resolved;
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
new_config = {
|
|
431
|
+
base: ssr ? assets_base(kit) : './',
|
|
432
|
+
build: {
|
|
433
|
+
cssCodeSplit: true,
|
|
434
|
+
outDir: `${out}/${ssr ? 'server' : 'client'}`,
|
|
435
|
+
rollupOptions: {
|
|
436
|
+
input,
|
|
437
|
+
output: {
|
|
438
|
+
format: 'esm',
|
|
439
|
+
entryFileNames: ssr ? '[name].js' : `${prefix}/[name]-[hash].js`,
|
|
440
|
+
chunkFileNames: ssr ? 'chunks/[name].js' : `${prefix}/chunks/[name]-[hash].js`,
|
|
441
|
+
assetFileNames: `${prefix}/assets/[name]-[hash][extname]`,
|
|
442
|
+
hoistTransitiveImports: false
|
|
443
|
+
},
|
|
444
|
+
preserveEntrySignatures: 'strict'
|
|
445
|
+
},
|
|
446
|
+
target: ssr ? 'node16.14' : undefined,
|
|
447
|
+
// don't use the default name to avoid collisions with 'static/manifest.json'
|
|
448
|
+
manifest: 'vite-manifest.json'
|
|
449
|
+
},
|
|
450
|
+
publicDir: ssr ? false : kit.files.assets,
|
|
451
|
+
worker: {
|
|
452
|
+
rollupOptions: {
|
|
453
|
+
output: {
|
|
454
|
+
entryFileNames: `${prefix}/workers/[name]-[hash].js`,
|
|
455
|
+
chunkFileNames: `${prefix}/workers/chunks/[name]-[hash].js`,
|
|
456
|
+
assetFileNames: `${prefix}/workers/assets/[name]-[hash][extname]`,
|
|
457
|
+
hoistTransitiveImports: false
|
|
458
|
+
}
|
|
459
|
+
}
|
|
480
460
|
}
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
|
|
461
|
+
};
|
|
462
|
+
} else {
|
|
463
|
+
new_config = {
|
|
464
|
+
appType: 'custom',
|
|
465
|
+
base: kit.paths.base,
|
|
466
|
+
build: {
|
|
467
|
+
rollupOptions: {
|
|
468
|
+
// Vite dependency crawler needs an explicit JS entry point
|
|
469
|
+
// eventhough server otherwise works without it
|
|
470
|
+
input: `${runtime_directory}/client/start.js`
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
publicDir: kit.files.assets
|
|
474
|
+
};
|
|
475
|
+
}
|
|
484
476
|
|
|
485
|
-
|
|
486
|
-
if (warning) console.error(warning);
|
|
477
|
+
warn_overridden_config(config, new_config);
|
|
487
478
|
|
|
488
|
-
return
|
|
479
|
+
return new_config;
|
|
489
480
|
},
|
|
490
481
|
|
|
491
482
|
/**
|
|
@@ -504,6 +495,33 @@ function kit({ svelte_config }) {
|
|
|
504
495
|
return preview(vite, vite_config, svelte_config);
|
|
505
496
|
},
|
|
506
497
|
|
|
498
|
+
/**
|
|
499
|
+
* Clears the output directories.
|
|
500
|
+
*/
|
|
501
|
+
buildStart() {
|
|
502
|
+
if (vite_config.build.ssr) return;
|
|
503
|
+
|
|
504
|
+
// Reset for new build. Goes here because `build --watch` calls buildStart but not config
|
|
505
|
+
completed_build = false;
|
|
506
|
+
|
|
507
|
+
if (is_build) {
|
|
508
|
+
if (!vite_config.build.watch) {
|
|
509
|
+
rimraf(out);
|
|
510
|
+
}
|
|
511
|
+
mkdirp(out);
|
|
512
|
+
}
|
|
513
|
+
},
|
|
514
|
+
|
|
515
|
+
generateBundle() {
|
|
516
|
+
if (vite_config.build.ssr) return;
|
|
517
|
+
|
|
518
|
+
this.emitFile({
|
|
519
|
+
type: 'asset',
|
|
520
|
+
fileName: `${kit.appDir}/version.json`,
|
|
521
|
+
source: JSON.stringify({ version: kit.version.name })
|
|
522
|
+
});
|
|
523
|
+
},
|
|
524
|
+
|
|
507
525
|
/**
|
|
508
526
|
* Vite builds a single bundle. We need three bundles: client, server, and service worker.
|
|
509
527
|
* The user's package.json scripts will invoke the Vite CLI to execute the client build. We
|
|
@@ -516,13 +534,11 @@ function kit({ svelte_config }) {
|
|
|
516
534
|
|
|
517
535
|
const guard = module_guard(this, {
|
|
518
536
|
cwd: vite.normalizePath(process.cwd()),
|
|
519
|
-
lib: vite.normalizePath(
|
|
537
|
+
lib: vite.normalizePath(kit.files.lib)
|
|
520
538
|
});
|
|
521
539
|
|
|
522
540
|
manifest_data.nodes.forEach((_node, i) => {
|
|
523
|
-
const id = vite.normalizePath(
|
|
524
|
-
path.resolve(svelte_config.kit.outDir, `generated/nodes/${i}.js`)
|
|
525
|
-
);
|
|
541
|
+
const id = vite.normalizePath(path.resolve(kit.outDir, `generated/nodes/${i}.js`));
|
|
526
542
|
|
|
527
543
|
guard.check(id);
|
|
528
544
|
});
|
|
@@ -544,26 +560,40 @@ function kit({ svelte_config }) {
|
|
|
544
560
|
vite_config,
|
|
545
561
|
vite_config_env,
|
|
546
562
|
manifest_data,
|
|
547
|
-
output_dir:
|
|
563
|
+
output_dir: out
|
|
548
564
|
};
|
|
549
|
-
|
|
565
|
+
|
|
566
|
+
/** @type {import('vite').Manifest} */
|
|
567
|
+
const vite_manifest = JSON.parse(
|
|
568
|
+
fs.readFileSync(`${out}/client/${vite_config.build.manifest}`, 'utf-8')
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
const client = {
|
|
572
|
+
assets,
|
|
573
|
+
chunks,
|
|
574
|
+
entry: find_deps(
|
|
575
|
+
vite_manifest,
|
|
576
|
+
posixify(path.relative('.', `${runtime_directory}/client/start.js`)),
|
|
577
|
+
false
|
|
578
|
+
),
|
|
579
|
+
vite_manifest
|
|
580
|
+
};
|
|
581
|
+
|
|
550
582
|
const server = await build_server(options, client);
|
|
551
583
|
|
|
552
|
-
const service_worker_entry_file = resolve_entry(
|
|
584
|
+
const service_worker_entry_file = resolve_entry(kit.files.serviceWorker);
|
|
553
585
|
|
|
554
586
|
/** @type {import('types').BuildData} */
|
|
555
587
|
build_data = {
|
|
556
|
-
app_dir:
|
|
557
|
-
app_path: `${
|
|
558
|
-
svelte_config.kit.paths.base ? '/' : ''
|
|
559
|
-
}${svelte_config.kit.appDir}`,
|
|
588
|
+
app_dir: kit.appDir,
|
|
589
|
+
app_path: `${kit.paths.base.slice(1)}${kit.paths.base ? '/' : ''}${kit.appDir}`,
|
|
560
590
|
manifest_data,
|
|
561
591
|
service_worker: !!service_worker_entry_file ? 'service-worker.js' : null, // TODO make file configurable?
|
|
562
592
|
client,
|
|
563
593
|
server
|
|
564
594
|
};
|
|
565
595
|
|
|
566
|
-
const manifest_path = `${
|
|
596
|
+
const manifest_path = `${out}/server/manifest-full.js`;
|
|
567
597
|
fs.writeFileSync(
|
|
568
598
|
manifest_path,
|
|
569
599
|
`export const manifest = ${generate_manifest({
|
|
@@ -575,7 +605,7 @@ function kit({ svelte_config }) {
|
|
|
575
605
|
|
|
576
606
|
log.info('Prerendering');
|
|
577
607
|
await new Promise((fulfil, reject) => {
|
|
578
|
-
const results_path = `${
|
|
608
|
+
const results_path = `${kit.outDir}/generated/prerendered.json`;
|
|
579
609
|
|
|
580
610
|
// do prerendering in a subprocess so any dangling stuff gets killed upon completion
|
|
581
611
|
const script = fileURLToPath(new URL('../../core/postbuild/index.js', import.meta.url));
|
|
@@ -615,7 +645,7 @@ function kit({ svelte_config }) {
|
|
|
615
645
|
|
|
616
646
|
// generate a new manifest that doesn't include prerendered pages
|
|
617
647
|
fs.writeFileSync(
|
|
618
|
-
`${
|
|
648
|
+
`${out}/server/manifest.js`,
|
|
619
649
|
`export const manifest = ${generate_manifest({
|
|
620
650
|
build_data,
|
|
621
651
|
relative_path: '.',
|
|
@@ -624,7 +654,7 @@ function kit({ svelte_config }) {
|
|
|
624
654
|
);
|
|
625
655
|
|
|
626
656
|
if (service_worker_entry_file) {
|
|
627
|
-
if (
|
|
657
|
+
if (kit.paths.assets) {
|
|
628
658
|
throw new Error('Cannot use service worker alongside config.kit.paths.assets');
|
|
629
659
|
}
|
|
630
660
|
|
|
@@ -659,7 +689,7 @@ function kit({ svelte_config }) {
|
|
|
659
689
|
return;
|
|
660
690
|
}
|
|
661
691
|
|
|
662
|
-
if (
|
|
692
|
+
if (kit.adapter) {
|
|
663
693
|
const { adapt } = await import('../../core/adapt/index.js');
|
|
664
694
|
await adapt(svelte_config, build_data, prerendered, prerender_map, { log });
|
|
665
695
|
} else {
|
|
@@ -672,13 +702,13 @@ function kit({ svelte_config }) {
|
|
|
672
702
|
}
|
|
673
703
|
|
|
674
704
|
// avoid making the manifest available to users
|
|
675
|
-
fs.unlinkSync(`${
|
|
676
|
-
fs.unlinkSync(`${
|
|
705
|
+
fs.unlinkSync(`${out}/client/${vite_config.build.manifest}`);
|
|
706
|
+
fs.unlinkSync(`${out}/server/${vite_config.build.manifest}`);
|
|
677
707
|
}
|
|
678
708
|
}
|
|
679
709
|
};
|
|
680
710
|
|
|
681
|
-
return [plugin_setup, plugin_compile];
|
|
711
|
+
return [plugin_setup, plugin_virtual_modules, plugin_compile];
|
|
682
712
|
}
|
|
683
713
|
|
|
684
714
|
/** @param {import('rollup').OutputBundle} bundle */
|
|
@@ -706,9 +736,9 @@ function warn_overridden_config(config, resolved_config) {
|
|
|
706
736
|
const overridden = find_overridden_config(config, resolved_config, enforced_config, '', []);
|
|
707
737
|
|
|
708
738
|
if (overridden.length > 0) {
|
|
709
|
-
|
|
739
|
+
console.error(
|
|
710
740
|
colors.bold().red('The following Vite config options will be overridden by SvelteKit:') +
|
|
711
|
-
|
|
741
|
+
overridden.map((key) => `\n - ${key}`).join('')
|
|
712
742
|
);
|
|
713
743
|
}
|
|
714
744
|
}
|
|
@@ -1,80 +1,8 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import {
|
|
3
|
-
import { runtime_directory } from '../../core/utils.js';
|
|
2
|
+
import { loadEnv } from 'vite';
|
|
4
3
|
import { posixify } from '../../utils/filesystem.js';
|
|
5
4
|
import { negotiate } from '../../utils/http.js';
|
|
6
5
|
|
|
7
|
-
/**
|
|
8
|
-
* @param {import('vite').ResolvedConfig} config
|
|
9
|
-
* @param {import('vite').ConfigEnv} config_env
|
|
10
|
-
* @return {Promise<import('vite').UserConfig>}
|
|
11
|
-
*/
|
|
12
|
-
export async function get_vite_config(config, config_env) {
|
|
13
|
-
const loaded = await loadConfigFromFile(
|
|
14
|
-
config_env,
|
|
15
|
-
config.configFile,
|
|
16
|
-
undefined,
|
|
17
|
-
config.logLevel
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
if (!loaded) {
|
|
21
|
-
throw new Error('Could not load Vite config');
|
|
22
|
-
}
|
|
23
|
-
return mergeConfig(loaded.config, {
|
|
24
|
-
// CLI opts
|
|
25
|
-
mode: config_env.mode,
|
|
26
|
-
logLevel: config.logLevel,
|
|
27
|
-
clearScreen: config.clearScreen,
|
|
28
|
-
optimizeDeps: { force: config.optimizeDeps.force }
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Takes zero or more objects and returns a new object that has all the values
|
|
34
|
-
* deeply merged together. None of the original objects will be mutated at any
|
|
35
|
-
* level, and the returned object will have no references to the original
|
|
36
|
-
* objects at any depth. If there's a conflict the last one wins, except for
|
|
37
|
-
* arrays which will be combined.
|
|
38
|
-
* @param {...Object} objects
|
|
39
|
-
* @returns {Record<string, any>} the merged object
|
|
40
|
-
*/
|
|
41
|
-
export function deep_merge(...objects) {
|
|
42
|
-
const result = {};
|
|
43
|
-
/** @type {string[]} */
|
|
44
|
-
objects.forEach((o) => merge_into(result, o));
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Merges b into a, recursively, mutating a.
|
|
50
|
-
* @param {Record<string, any>} a
|
|
51
|
-
* @param {Record<string, any>} b
|
|
52
|
-
*/
|
|
53
|
-
function merge_into(a, b) {
|
|
54
|
-
/**
|
|
55
|
-
* Checks for "plain old Javascript object", typically made as an object
|
|
56
|
-
* literal. Excludes Arrays and built-in types like Buffer.
|
|
57
|
-
* @param {any} x
|
|
58
|
-
*/
|
|
59
|
-
const is_plain_object = (x) => typeof x === 'object' && x.constructor === Object;
|
|
60
|
-
|
|
61
|
-
for (const prop in b) {
|
|
62
|
-
if (is_plain_object(b[prop])) {
|
|
63
|
-
if (!is_plain_object(a[prop])) {
|
|
64
|
-
a[prop] = {};
|
|
65
|
-
}
|
|
66
|
-
merge_into(a[prop], b[prop]);
|
|
67
|
-
} else if (Array.isArray(b[prop])) {
|
|
68
|
-
if (!Array.isArray(a[prop])) {
|
|
69
|
-
a[prop] = [];
|
|
70
|
-
}
|
|
71
|
-
a[prop].push(...b[prop]);
|
|
72
|
-
} else {
|
|
73
|
-
a[prop] = b[prop];
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
6
|
/**
|
|
79
7
|
* Transforms kit.alias to a valid vite.resolve.alias array.
|
|
80
8
|
*
|
|
@@ -115,21 +43,6 @@ export function get_config_aliases(config) {
|
|
|
115
43
|
return alias;
|
|
116
44
|
}
|
|
117
45
|
|
|
118
|
-
/**
|
|
119
|
-
* Returns Vite aliases for generated and runtime files.
|
|
120
|
-
*
|
|
121
|
-
* @param {import('types').ValidatedKitConfig} config
|
|
122
|
-
* */
|
|
123
|
-
export function get_app_aliases(config) {
|
|
124
|
-
/** @type {import('vite').Alias[]} */
|
|
125
|
-
const alias = [
|
|
126
|
-
{ find: '__GENERATED__', replacement: path.posix.join(config.outDir, 'generated') },
|
|
127
|
-
{ find: '$app', replacement: `${runtime_directory}/app` }
|
|
128
|
-
];
|
|
129
|
-
|
|
130
|
-
return alias;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
46
|
/**
|
|
134
47
|
* @param {string} str
|
|
135
48
|
*/
|
|
@@ -1389,10 +1389,17 @@ export function create_client({ target, base }) {
|
|
|
1389
1389
|
const a = find_anchor(/** @type {Element} */ (event.composedPath()[0]), container);
|
|
1390
1390
|
if (!a) return;
|
|
1391
1391
|
|
|
1392
|
-
const { url, external,
|
|
1393
|
-
const options = get_router_options(a);
|
|
1392
|
+
const { url, external, target } = get_link_info(a, base);
|
|
1394
1393
|
if (!url) return;
|
|
1395
1394
|
|
|
1395
|
+
// bail out before `beforeNavigate` if link opens in a different tab
|
|
1396
|
+
if (target === '_parent' || target === '_top') {
|
|
1397
|
+
if (window.parent !== window) return;
|
|
1398
|
+
} else if (target && target !== '_self') {
|
|
1399
|
+
return;
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
const options = get_router_options(a);
|
|
1396
1403
|
const is_svg_a_element = a instanceof SVGAElement;
|
|
1397
1404
|
|
|
1398
1405
|
// Ignore URL protocols that differ to the current one and are not http(s) (e.g. `mailto:`, `tel:`, `myapp:`, etc.)
|
|
@@ -1410,8 +1417,6 @@ export function create_client({ target, base }) {
|
|
|
1410
1417
|
)
|
|
1411
1418
|
return;
|
|
1412
1419
|
|
|
1413
|
-
if (has.download) return;
|
|
1414
|
-
|
|
1415
1420
|
// Ignore the following but fire beforeNavigate
|
|
1416
1421
|
if (external || options.reload) {
|
|
1417
1422
|
const navigation = before_navigate({ url, type: 'link' });
|
|
@@ -1732,7 +1737,7 @@ if (DEV) {
|
|
|
1732
1737
|
console.warn = function warn(...args) {
|
|
1733
1738
|
if (
|
|
1734
1739
|
args.length === 1 &&
|
|
1735
|
-
/<(Layout|Page)(_[\w$]+)?> was created (with unknown|without expected) prop '(data|form)'/.test(
|
|
1740
|
+
/<(Layout|Page|Error)(_[\w$]+)?> was created (with unknown|without expected) prop '(data|form)'/.test(
|
|
1736
1741
|
args[0]
|
|
1737
1742
|
)
|
|
1738
1743
|
) {
|
|
@@ -124,16 +124,16 @@ export function get_link_info(a, base) {
|
|
|
124
124
|
url = new URL(a instanceof SVGAElement ? a.href.baseVal : a.href, document.baseURI);
|
|
125
125
|
} catch {}
|
|
126
126
|
|
|
127
|
-
const
|
|
128
|
-
rel_external: (a.getAttribute('rel') || '').split(/\s+/).includes('external'),
|
|
129
|
-
download: a.hasAttribute('download'),
|
|
130
|
-
target: !!(a instanceof SVGAElement ? a.target.baseVal : a.target)
|
|
131
|
-
};
|
|
127
|
+
const target = a instanceof SVGAElement ? a.target.baseVal : a.target;
|
|
132
128
|
|
|
133
129
|
const external =
|
|
134
|
-
!url ||
|
|
130
|
+
!url ||
|
|
131
|
+
!!target ||
|
|
132
|
+
is_external_url(url, base) ||
|
|
133
|
+
(a.getAttribute('rel') || '').split(/\s+/).includes('external') ||
|
|
134
|
+
a.hasAttribute('download');
|
|
135
135
|
|
|
136
|
-
return { url,
|
|
136
|
+
return { url, external, target };
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
/**
|
package/types/ambient.d.ts
CHANGED
|
@@ -11,9 +11,12 @@
|
|
|
11
11
|
* }
|
|
12
12
|
* }
|
|
13
13
|
*
|
|
14
|
-
* export
|
|
14
|
+
* export {};
|
|
15
15
|
* ```
|
|
16
16
|
*
|
|
17
|
+
* The `export {}` line exists because without it, the file would be treated as an _ambient module_ which prevents you from adding `import` declarations.
|
|
18
|
+
* If you need to add ambient `declare module` declarations, do so in a separate file like `src/ambient.d.ts`.
|
|
19
|
+
*
|
|
17
20
|
* By populating these interfaces, you will gain type safety when using `event.locals`, `event.platform`, and `data` from `load` functions.
|
|
18
21
|
*/
|
|
19
22
|
declare namespace App {
|
|
@@ -37,7 +40,7 @@ declare namespace App {
|
|
|
37
40
|
export interface PageData {}
|
|
38
41
|
|
|
39
42
|
/**
|
|
40
|
-
* If your adapter provides [platform-specific context](https://kit.svelte.dev/docs/adapters#
|
|
43
|
+
* If your adapter provides [platform-specific context](https://kit.svelte.dev/docs/adapters#platform-specific-context) via `event.platform`, you can specify it here.
|
|
41
44
|
*/
|
|
42
45
|
export interface Platform {}
|
|
43
46
|
}
|
|
@@ -243,7 +246,8 @@ declare module '$app/navigation' {
|
|
|
243
246
|
|
|
244
247
|
/**
|
|
245
248
|
* A navigation interceptor that triggers before we navigate to a new URL, whether by clicking a link, calling `goto(...)`, or using the browser back/forward controls.
|
|
246
|
-
* Calling `cancel()` will prevent the navigation from completing.
|
|
249
|
+
* Calling `cancel()` will prevent the navigation from completing. If the navigation would have directly unloaded the current page, calling `cancel` will trigger the native
|
|
250
|
+
* browser unload confirmation dialog. In these cases, `navigation.willUnload` is `true`.
|
|
247
251
|
*
|
|
248
252
|
* When a navigation isn't client side, `navigation.to.route.id` will be `null`.
|
|
249
253
|
*
|