@sveltejs/kit 1.0.0-next.43 → 1.0.0-next.430
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/package.json +95 -63
- package/src/cli.js +112 -0
- package/src/core/adapt/builder.js +207 -0
- package/src/core/adapt/index.js +19 -0
- package/src/core/config/index.js +86 -0
- package/src/core/config/options.js +488 -0
- package/src/core/config/types.d.ts +1 -0
- package/src/core/constants.js +5 -0
- package/src/core/env.js +97 -0
- package/src/core/generate_manifest/index.js +99 -0
- package/src/core/prerender/crawl.js +194 -0
- package/src/core/prerender/prerender.js +378 -0
- package/src/core/prerender/queue.js +80 -0
- package/src/core/sync/create_manifest_data/index.js +506 -0
- package/src/core/sync/create_manifest_data/types.d.ts +40 -0
- package/src/core/sync/sync.js +59 -0
- package/src/core/sync/utils.js +44 -0
- package/src/core/sync/write_ambient.js +27 -0
- package/src/core/sync/write_client_manifest.js +82 -0
- package/src/core/sync/write_matchers.js +25 -0
- package/src/core/sync/write_root.js +91 -0
- package/src/core/sync/write_tsconfig.js +195 -0
- package/src/core/sync/write_types.js +775 -0
- package/src/core/utils.js +70 -0
- package/src/hooks.js +26 -0
- package/src/index/index.js +45 -0
- package/src/index/private.js +33 -0
- package/src/node/index.js +145 -0
- package/src/node/polyfills.js +40 -0
- package/src/runtime/app/env.js +11 -0
- package/src/runtime/app/navigation.js +22 -0
- package/src/runtime/app/paths.js +1 -0
- package/src/runtime/app/stores.js +102 -0
- package/src/runtime/client/ambient.d.ts +17 -0
- package/src/runtime/client/client.js +1289 -0
- package/src/runtime/client/fetcher.js +60 -0
- package/src/runtime/client/parse.js +36 -0
- package/src/runtime/client/singletons.js +21 -0
- package/src/runtime/client/start.js +46 -0
- package/src/runtime/client/types.d.ts +105 -0
- package/src/runtime/client/utils.js +113 -0
- package/src/runtime/components/error.svelte +16 -0
- package/{assets → src/runtime}/components/layout.svelte +0 -0
- package/src/runtime/env/dynamic/private.js +1 -0
- package/src/runtime/env/dynamic/public.js +1 -0
- package/src/runtime/env-private.js +7 -0
- package/src/runtime/env-public.js +7 -0
- package/src/runtime/env.js +6 -0
- package/src/runtime/hash.js +16 -0
- package/src/runtime/paths.js +11 -0
- package/src/runtime/server/endpoint.js +58 -0
- package/src/runtime/server/index.js +448 -0
- package/src/runtime/server/page/cookie.js +25 -0
- package/src/runtime/server/page/crypto.js +239 -0
- package/src/runtime/server/page/csp.js +249 -0
- package/src/runtime/server/page/fetch.js +266 -0
- package/src/runtime/server/page/index.js +416 -0
- package/src/runtime/server/page/load_data.js +135 -0
- package/src/runtime/server/page/render.js +362 -0
- package/src/runtime/server/page/respond_with_error.js +94 -0
- package/src/runtime/server/page/types.d.ts +44 -0
- package/src/runtime/server/utils.js +116 -0
- package/src/utils/error.js +22 -0
- package/src/utils/escape.js +104 -0
- package/src/utils/filesystem.js +108 -0
- package/src/utils/http.js +55 -0
- package/src/utils/misc.js +1 -0
- package/src/utils/routing.js +108 -0
- package/src/utils/url.js +97 -0
- package/src/vite/build/build_server.js +337 -0
- package/src/vite/build/build_service_worker.js +90 -0
- package/src/vite/build/utils.js +160 -0
- package/src/vite/dev/index.js +551 -0
- package/src/vite/index.js +574 -0
- package/src/vite/preview/index.js +186 -0
- package/src/vite/types.d.ts +3 -0
- package/src/vite/utils.js +345 -0
- package/svelte-kit.js +1 -1
- package/types/ambient.d.ts +357 -0
- package/types/index.d.ts +343 -0
- package/types/internal.d.ts +308 -0
- package/types/private.d.ts +209 -0
- package/CHANGELOG.md +0 -431
- package/assets/components/error.svelte +0 -13
- package/assets/runtime/app/env.js +0 -5
- package/assets/runtime/app/navigation.js +0 -41
- package/assets/runtime/app/paths.js +0 -1
- package/assets/runtime/app/stores.js +0 -93
- package/assets/runtime/chunks/utils.js +0 -19
- package/assets/runtime/internal/singletons.js +0 -23
- package/assets/runtime/internal/start.js +0 -770
- package/assets/runtime/paths.js +0 -12
- package/dist/.DS_Store +0 -0
- package/dist/chunks/index.js +0 -3521
- package/dist/chunks/index2.js +0 -587
- package/dist/chunks/index3.js +0 -246
- package/dist/chunks/index4.js +0 -538
- package/dist/chunks/index5.js +0 -761
- package/dist/chunks/index6.js +0 -322
- package/dist/chunks/standard.js +0 -99
- package/dist/chunks/utils.js +0 -83
- package/dist/cli.js +0 -546
- package/dist/ssr.js +0 -2581
package/dist/chunks/index4.js
DELETED
|
@@ -1,538 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { r as rimraf, c as copy_assets } from './utils.js';
|
|
4
|
-
import { c as create_manifest_data, a as create_app } from './index2.js';
|
|
5
|
-
import vite from 'vite';
|
|
6
|
-
import svelte from '@svitejs/vite-plugin-svelte';
|
|
7
|
-
import '../cli.js';
|
|
8
|
-
import 'sade';
|
|
9
|
-
import 'url';
|
|
10
|
-
import './standard.js';
|
|
11
|
-
|
|
12
|
-
/** @param {any} value */
|
|
13
|
-
const s = (value) => JSON.stringify(value);
|
|
14
|
-
|
|
15
|
-
/** @typedef {Record<string, {
|
|
16
|
-
* file: string;
|
|
17
|
-
* css: string[];
|
|
18
|
-
* imports: string[];
|
|
19
|
-
* }>} ClientManifest */
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @param {import('../../types').ValidatedConfig} config
|
|
23
|
-
* @param {{
|
|
24
|
-
* cwd?: string;
|
|
25
|
-
* runtime?: string;
|
|
26
|
-
* }} [opts]
|
|
27
|
-
*/
|
|
28
|
-
async function build(config, { cwd = process.cwd(), runtime = '@sveltejs/kit/ssr' } = {}) {
|
|
29
|
-
const build_dir = path.resolve(cwd, '.svelte/build');
|
|
30
|
-
|
|
31
|
-
rimraf(build_dir);
|
|
32
|
-
|
|
33
|
-
const options = {
|
|
34
|
-
cwd,
|
|
35
|
-
config,
|
|
36
|
-
build_dir,
|
|
37
|
-
base:
|
|
38
|
-
config.kit.paths.assets === '/.'
|
|
39
|
-
? `/${config.kit.appDir}/`
|
|
40
|
-
: `${config.kit.paths.assets}/${config.kit.appDir}/`,
|
|
41
|
-
manifest: create_manifest_data({
|
|
42
|
-
config,
|
|
43
|
-
output: build_dir,
|
|
44
|
-
cwd
|
|
45
|
-
}),
|
|
46
|
-
output_dir: path.resolve(cwd, '.svelte/output'),
|
|
47
|
-
client_entry_file: '.svelte/build/runtime/internal/start.js',
|
|
48
|
-
service_worker_entry_file: resolve_entry(config.kit.files.serviceWorker)
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const client_manifest = await build_client(options);
|
|
52
|
-
await build_server(options, client_manifest, runtime);
|
|
53
|
-
|
|
54
|
-
if (options.service_worker_entry_file) {
|
|
55
|
-
const { base, assets } = config.kit.paths;
|
|
56
|
-
|
|
57
|
-
if (assets !== base && assets !== '/.') {
|
|
58
|
-
throw new Error('Cannot use service worker alongside config.kit.paths.assets');
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
await build_service_worker(options, client_manifest);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @param {{
|
|
67
|
-
* cwd: string;
|
|
68
|
-
* base: string;
|
|
69
|
-
* config: import('../../types').ValidatedConfig
|
|
70
|
-
* manifest: import('../../types').ManifestData
|
|
71
|
-
* build_dir: string;
|
|
72
|
-
* output_dir: string;
|
|
73
|
-
* client_entry_file: string;
|
|
74
|
-
* service_worker_entry_file: string;
|
|
75
|
-
* }} options
|
|
76
|
-
*/
|
|
77
|
-
async function build_client({
|
|
78
|
-
cwd,
|
|
79
|
-
base,
|
|
80
|
-
config,
|
|
81
|
-
manifest,
|
|
82
|
-
build_dir,
|
|
83
|
-
output_dir,
|
|
84
|
-
client_entry_file,
|
|
85
|
-
service_worker_entry_file
|
|
86
|
-
}) {
|
|
87
|
-
create_app({
|
|
88
|
-
manifest_data: manifest,
|
|
89
|
-
output: build_dir,
|
|
90
|
-
cwd
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
copy_assets(build_dir);
|
|
94
|
-
|
|
95
|
-
process.env.VITE_SVELTEKIT_AMP = config.kit.amp ? 'true' : '';
|
|
96
|
-
process.env.VITE_SVELTEKIT_SERVICE_WORKER = service_worker_entry_file ? '/service-worker.js' : '';
|
|
97
|
-
|
|
98
|
-
const client_out_dir = `${output_dir}/client/${config.kit.appDir}`;
|
|
99
|
-
const client_manifest_file = `${client_out_dir}/manifest.json`;
|
|
100
|
-
|
|
101
|
-
/** @type {Record<string, string>} */
|
|
102
|
-
const input = {
|
|
103
|
-
start: path.resolve(cwd, client_entry_file)
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
manifest.pages.forEach((page) => {
|
|
107
|
-
page.parts.forEach((file) => {
|
|
108
|
-
const resolved = path.resolve(cwd, file);
|
|
109
|
-
const relative = path.relative(config.kit.files.routes, resolved);
|
|
110
|
-
input[path.join('pages', relative)] = resolved;
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
manifest.endpoints.forEach((endpoint) => {
|
|
115
|
-
const resolved = path.resolve(cwd, endpoint.file);
|
|
116
|
-
const relative = path.relative(config.kit.files.routes, resolved);
|
|
117
|
-
input[path.join('endpoints', relative)] = resolved;
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// client build
|
|
121
|
-
await vite.build({
|
|
122
|
-
root: cwd,
|
|
123
|
-
base,
|
|
124
|
-
build: {
|
|
125
|
-
cssCodeSplit: true,
|
|
126
|
-
manifest: true,
|
|
127
|
-
lib: {
|
|
128
|
-
// TODO i'm not convinced this block is necessary if we're
|
|
129
|
-
// providing inputs explicitly via rollupOptions, but without
|
|
130
|
-
// it Vite complains about the dynamic import polyfill
|
|
131
|
-
entry: client_entry_file,
|
|
132
|
-
name: 'app',
|
|
133
|
-
formats: ['es']
|
|
134
|
-
},
|
|
135
|
-
outDir: client_out_dir,
|
|
136
|
-
rollupOptions: {
|
|
137
|
-
input,
|
|
138
|
-
output: {
|
|
139
|
-
entryFileNames: '[name]-[hash].js',
|
|
140
|
-
chunkFileNames: 'chunks/[name]-[hash].js',
|
|
141
|
-
assetFileNames: 'assets/[name]-[hash][extname]'
|
|
142
|
-
},
|
|
143
|
-
preserveEntrySignatures: 'strict'
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
resolve: {
|
|
147
|
-
alias: {
|
|
148
|
-
$app: path.resolve(`${build_dir}/runtime/app`)
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
plugins: [
|
|
152
|
-
svelte({
|
|
153
|
-
emitCss: true,
|
|
154
|
-
compilerOptions: {
|
|
155
|
-
dev: true,
|
|
156
|
-
hydratable: true
|
|
157
|
-
},
|
|
158
|
-
hot: true,
|
|
159
|
-
extensions: config.extensions
|
|
160
|
-
})
|
|
161
|
-
]
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
/** @type {ClientManifest} */
|
|
165
|
-
const client_manifest = JSON.parse(fs.readFileSync(client_manifest_file, 'utf-8'));
|
|
166
|
-
fs.unlinkSync(client_manifest_file);
|
|
167
|
-
|
|
168
|
-
return client_manifest;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* @param {{
|
|
173
|
-
* cwd: string;
|
|
174
|
-
* base: string;
|
|
175
|
-
* config: import('../../types').ValidatedConfig
|
|
176
|
-
* manifest: import('../../types').ManifestData
|
|
177
|
-
* build_dir: string;
|
|
178
|
-
* output_dir: string;
|
|
179
|
-
* client_entry_file: string;
|
|
180
|
-
* service_worker_entry_file: string;
|
|
181
|
-
* }} options
|
|
182
|
-
* @param {ClientManifest} client_manifest
|
|
183
|
-
* @param {string} runtime
|
|
184
|
-
*/
|
|
185
|
-
async function build_server(
|
|
186
|
-
{ cwd, base, config, manifest, build_dir, output_dir, client_entry_file },
|
|
187
|
-
client_manifest,
|
|
188
|
-
runtime
|
|
189
|
-
) {
|
|
190
|
-
let setup_file = resolve_entry(config.kit.files.setup);
|
|
191
|
-
if (!fs.existsSync(setup_file)) {
|
|
192
|
-
setup_file = path.resolve(cwd, '.svelte/build/setup.js');
|
|
193
|
-
fs.writeFileSync(setup_file, '');
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const app_file = `${build_dir}/app.js`;
|
|
197
|
-
|
|
198
|
-
/** @type {(file: string) => string} */
|
|
199
|
-
const app_relative = (file) => {
|
|
200
|
-
const relative_file = path.relative(build_dir, path.resolve(cwd, file));
|
|
201
|
-
return relative_file[0] === '.' ? relative_file : `./${relative_file}`;
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
const component_indexes = new Map();
|
|
205
|
-
manifest.components.forEach((c, i) => {
|
|
206
|
-
component_indexes.set(c, i);
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
/** @param {string} c */
|
|
210
|
-
const stringify_component = (c) => `() => import(${s(`${app_relative(c)}`)})`;
|
|
211
|
-
|
|
212
|
-
const entry = `${config.kit.paths.assets}/${config.kit.appDir}/${client_manifest[client_entry_file].file}`;
|
|
213
|
-
|
|
214
|
-
const common_js_deps = new Set();
|
|
215
|
-
const common_css_deps = new Set();
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* @param {string} id
|
|
219
|
-
* @param {Set<string>} js_deps
|
|
220
|
-
* @param {Set<string>} css_deps
|
|
221
|
-
*/
|
|
222
|
-
function find_deps(id, js_deps, css_deps) {
|
|
223
|
-
const chunk = client_manifest[id];
|
|
224
|
-
js_deps.add(chunk.file);
|
|
225
|
-
|
|
226
|
-
if (chunk.css) {
|
|
227
|
-
chunk.css.forEach((file) => css_deps.add(file));
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (chunk.imports) {
|
|
231
|
-
chunk.imports.forEach((id) => find_deps(id, js_deps, css_deps));
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
find_deps(client_entry_file, common_js_deps, common_css_deps);
|
|
236
|
-
|
|
237
|
-
// TODO ideally we wouldn't embed the css_lookup, but this is the easiest
|
|
238
|
-
// way to be able to inline CSS into AMP documents. if we come up with
|
|
239
|
-
// something better, we could use it for non-AMP documents too, as
|
|
240
|
-
// critical CSS below a certain threshold _should_ be inlined
|
|
241
|
-
const deps = {};
|
|
242
|
-
const amp_css_lookup = {};
|
|
243
|
-
manifest.pages.forEach((data) => {
|
|
244
|
-
data.parts.forEach((file) => {
|
|
245
|
-
/** @type {Record<string, { js: Set<string>, css: Set<string> }>} */
|
|
246
|
-
deps[file] = {
|
|
247
|
-
js: new Set(common_js_deps),
|
|
248
|
-
css: new Set(common_css_deps)
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
find_deps(file, deps[file].js, deps[file].css);
|
|
252
|
-
|
|
253
|
-
Array.from(deps[file].css).forEach((file) => {
|
|
254
|
-
const resolved = `${output_dir}/client/${config.kit.appDir}/${file}`;
|
|
255
|
-
const contents = fs.readFileSync(resolved, 'utf-8');
|
|
256
|
-
|
|
257
|
-
amp_css_lookup[`/${config.kit.appDir}/${file}`] = contents;
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
const prefix =
|
|
263
|
-
config.kit.paths.assets === '/.'
|
|
264
|
-
? `/${config.kit.appDir}`
|
|
265
|
-
: `${config.kit.paths.assets}/${config.kit.appDir}`;
|
|
266
|
-
|
|
267
|
-
// prettier-ignore
|
|
268
|
-
fs.writeFileSync(
|
|
269
|
-
app_file,
|
|
270
|
-
`
|
|
271
|
-
import { ssr } from '${runtime}';
|
|
272
|
-
import root from './generated/root.svelte';
|
|
273
|
-
import { set_paths } from './runtime/paths.js';
|
|
274
|
-
import * as setup from ${s(app_relative(setup_file))};
|
|
275
|
-
|
|
276
|
-
const template = ({ head, body }) => ${s(fs.readFileSync(config.kit.files.template, 'utf-8'))
|
|
277
|
-
.replace('%svelte.head%', '" + head + "')
|
|
278
|
-
.replace('%svelte.body%', '" + body + "')};
|
|
279
|
-
|
|
280
|
-
set_paths(${s(config.kit.paths)});
|
|
281
|
-
|
|
282
|
-
// allow paths to be overridden in svelte-kit start
|
|
283
|
-
export function init({ paths }) {
|
|
284
|
-
set_paths(paths);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
const d = decodeURIComponent;
|
|
288
|
-
const empty = () => ({});
|
|
289
|
-
|
|
290
|
-
const components = [
|
|
291
|
-
${manifest.components.map((c) => stringify_component(c)).join(',\n\t\t\t\t')}
|
|
292
|
-
];
|
|
293
|
-
|
|
294
|
-
${config.kit.amp ? `
|
|
295
|
-
const amp_css_lookup = ${s(amp_css_lookup)};` : ''}
|
|
296
|
-
|
|
297
|
-
const manifest = {
|
|
298
|
-
assets: ${s(manifest.assets)},
|
|
299
|
-
layout: ${stringify_component(manifest.layout)},
|
|
300
|
-
error: ${stringify_component(manifest.error)},
|
|
301
|
-
pages: [
|
|
302
|
-
${manifest.pages
|
|
303
|
-
.map((data) => {
|
|
304
|
-
const params = get_params(data.params);
|
|
305
|
-
const parts = data.parts.map(c => `components[${component_indexes.get(c)}]`);
|
|
306
|
-
|
|
307
|
-
const js_deps = new Set();
|
|
308
|
-
const css_deps = new Set();
|
|
309
|
-
|
|
310
|
-
for (const file of data.parts) {
|
|
311
|
-
const { js, css } = deps[file];
|
|
312
|
-
|
|
313
|
-
js.forEach(asset => {
|
|
314
|
-
js_deps.add(`${prefix}/${asset}`);
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
css.forEach(asset => {
|
|
318
|
-
css_deps.add(`${prefix}/${asset}`);
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
return `{
|
|
323
|
-
pattern: ${data.pattern},
|
|
324
|
-
params: ${params},
|
|
325
|
-
parts: [${parts.join(', ')}],
|
|
326
|
-
css: [${Array.from(css_deps).map(s).join(', ')}],
|
|
327
|
-
js: [${Array.from(js_deps).map(s).join(', ')}]
|
|
328
|
-
}`;
|
|
329
|
-
})
|
|
330
|
-
.join(',\n\t\t\t\t\t')}
|
|
331
|
-
],
|
|
332
|
-
endpoints: [
|
|
333
|
-
${manifest.endpoints
|
|
334
|
-
.map((data) => {
|
|
335
|
-
const params = get_params(data.params);
|
|
336
|
-
const load = `() => import(${s(app_relative(data.file))})`;
|
|
337
|
-
|
|
338
|
-
return `{ pattern: ${data.pattern}, params: ${params}, load: ${load} }`;
|
|
339
|
-
})
|
|
340
|
-
.join(',\n\t\t\t\t\t')}
|
|
341
|
-
]
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
export function render(request, {
|
|
345
|
-
paths = ${s(config.kit.paths)},
|
|
346
|
-
local = false,
|
|
347
|
-
only_prerender = false,
|
|
348
|
-
get_static_file
|
|
349
|
-
} = {}) {
|
|
350
|
-
return ssr(request, {
|
|
351
|
-
paths,
|
|
352
|
-
local,
|
|
353
|
-
template,
|
|
354
|
-
manifest,
|
|
355
|
-
target: ${s(config.kit.target)},${
|
|
356
|
-
config.kit.startGlobal ? `\n\t\t\t\t\tstart_global: ${s(config.kit.startGlobal)},` : ''
|
|
357
|
-
}
|
|
358
|
-
entry: ${s(entry)},
|
|
359
|
-
root,
|
|
360
|
-
setup,
|
|
361
|
-
dev: false,
|
|
362
|
-
amp: ${config.kit.amp},
|
|
363
|
-
only_prerender,
|
|
364
|
-
app_dir: ${s(config.kit.appDir)},
|
|
365
|
-
host: ${s(config.kit.host)},
|
|
366
|
-
host_header: ${s(config.kit.hostHeader)},
|
|
367
|
-
get_stack: error => error.stack,
|
|
368
|
-
get_static_file,
|
|
369
|
-
get_amp_css: dep => amp_css_lookup[dep]
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
`
|
|
373
|
-
.replace(/^\t{3}/gm, '')
|
|
374
|
-
.trim()
|
|
375
|
-
);
|
|
376
|
-
|
|
377
|
-
await vite.build({
|
|
378
|
-
root: cwd,
|
|
379
|
-
base,
|
|
380
|
-
build: {
|
|
381
|
-
ssr: true,
|
|
382
|
-
lib: {
|
|
383
|
-
entry: app_file,
|
|
384
|
-
name: 'app',
|
|
385
|
-
formats: ['es']
|
|
386
|
-
},
|
|
387
|
-
outDir: `${output_dir}/server`
|
|
388
|
-
},
|
|
389
|
-
resolve: {
|
|
390
|
-
alias: {
|
|
391
|
-
$app: path.resolve(`${build_dir}/runtime/app`)
|
|
392
|
-
}
|
|
393
|
-
},
|
|
394
|
-
plugins: [
|
|
395
|
-
svelte({
|
|
396
|
-
emitCss: true,
|
|
397
|
-
compilerOptions: {
|
|
398
|
-
dev: true,
|
|
399
|
-
hydratable: true
|
|
400
|
-
},
|
|
401
|
-
hot: true,
|
|
402
|
-
extensions: config.extensions
|
|
403
|
-
})
|
|
404
|
-
],
|
|
405
|
-
ssr: {
|
|
406
|
-
noExternal: ['svelte']
|
|
407
|
-
},
|
|
408
|
-
optimizeDeps: {
|
|
409
|
-
entries: []
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* @param {{
|
|
416
|
-
* cwd: string;
|
|
417
|
-
* base: string;
|
|
418
|
-
* config: import('../../types').ValidatedConfig
|
|
419
|
-
* manifest: import('../../types').ManifestData
|
|
420
|
-
* build_dir: string;
|
|
421
|
-
* output_dir: string;
|
|
422
|
-
* client_entry_file: string;
|
|
423
|
-
* service_worker_entry_file: string;
|
|
424
|
-
* }} options
|
|
425
|
-
* @param {ClientManifest} client_manifest
|
|
426
|
-
*/
|
|
427
|
-
async function build_service_worker(
|
|
428
|
-
{ cwd, base, config, manifest, build_dir, output_dir, service_worker_entry_file },
|
|
429
|
-
client_manifest
|
|
430
|
-
) {
|
|
431
|
-
// TODO add any assets referenced in template .html file, e.g. favicon?
|
|
432
|
-
const app_files = new Set();
|
|
433
|
-
for (const key in client_manifest) {
|
|
434
|
-
const { file, css } = client_manifest[key];
|
|
435
|
-
app_files.add(file);
|
|
436
|
-
if (css) {
|
|
437
|
-
css.forEach((file) => {
|
|
438
|
-
app_files.add(file);
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
fs.writeFileSync(
|
|
444
|
-
`${build_dir}/runtime/service-worker.js`,
|
|
445
|
-
`
|
|
446
|
-
export const timestamp = ${Date.now()};
|
|
447
|
-
|
|
448
|
-
export const build = [
|
|
449
|
-
${Array.from(app_files)
|
|
450
|
-
.map((file) => `${s(`${config.kit.paths.base}/${config.kit.appDir}/${file}`)}`)
|
|
451
|
-
.join(',\n\t\t\t\t')}
|
|
452
|
-
];
|
|
453
|
-
|
|
454
|
-
export const assets = [
|
|
455
|
-
${manifest.assets
|
|
456
|
-
.map((asset) => `${s(`${config.kit.paths.base}/${asset.file}`)}`)
|
|
457
|
-
.join(',\n\t\t\t\t')}
|
|
458
|
-
];
|
|
459
|
-
`
|
|
460
|
-
.replace(/^\t{3}/gm, '')
|
|
461
|
-
.trim()
|
|
462
|
-
);
|
|
463
|
-
|
|
464
|
-
await vite.build({
|
|
465
|
-
root: cwd,
|
|
466
|
-
base,
|
|
467
|
-
build: {
|
|
468
|
-
lib: {
|
|
469
|
-
entry: service_worker_entry_file,
|
|
470
|
-
name: 'app',
|
|
471
|
-
formats: ['es']
|
|
472
|
-
},
|
|
473
|
-
rollupOptions: {
|
|
474
|
-
output: {
|
|
475
|
-
entryFileNames: 'service-worker.js'
|
|
476
|
-
}
|
|
477
|
-
},
|
|
478
|
-
outDir: `${output_dir}/client`,
|
|
479
|
-
emptyOutDir: false
|
|
480
|
-
},
|
|
481
|
-
resolve: {
|
|
482
|
-
alias: {
|
|
483
|
-
'$service-worker': path.resolve(`${build_dir}/runtime/service-worker`)
|
|
484
|
-
}
|
|
485
|
-
},
|
|
486
|
-
optimizeDeps: {
|
|
487
|
-
entries: []
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* @param {string} entry
|
|
494
|
-
* @returns {string}
|
|
495
|
-
*/
|
|
496
|
-
function resolve_entry(entry) {
|
|
497
|
-
if (fs.existsSync(entry)) {
|
|
498
|
-
const stats = fs.statSync(entry);
|
|
499
|
-
if (stats.isDirectory()) {
|
|
500
|
-
return resolve_entry(path.join(entry, 'index'));
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
return entry;
|
|
504
|
-
} else {
|
|
505
|
-
const dir = path.dirname(entry);
|
|
506
|
-
|
|
507
|
-
if (fs.existsSync(dir)) {
|
|
508
|
-
const base = path.basename(entry);
|
|
509
|
-
const files = fs.readdirSync(dir);
|
|
510
|
-
|
|
511
|
-
const found = files.find((file) => file.replace(/\.[^.]+$/, '') === base);
|
|
512
|
-
|
|
513
|
-
if (found) return path.join(dir, found);
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
return null;
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
/** @param {string[]} array */
|
|
521
|
-
function get_params(array) {
|
|
522
|
-
// given an array of params like `['x', 'y', 'z']` for
|
|
523
|
-
// src/routes/[x]/[y]/[z]/svelte, create a function
|
|
524
|
-
// that turns a RexExpMatchArray into ({ x, y, z })
|
|
525
|
-
return array.length
|
|
526
|
-
? '(m) => ({ ' +
|
|
527
|
-
array
|
|
528
|
-
.map((param, i) => {
|
|
529
|
-
return param.startsWith('...')
|
|
530
|
-
? `${param.slice(3)}: d(m[${i + 1}]).split('/')`
|
|
531
|
-
: `${param}: d(m[${i + 1}])`;
|
|
532
|
-
})
|
|
533
|
-
.join(', ') +
|
|
534
|
-
'})'
|
|
535
|
-
: 'empty';
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
export { build };
|