@sveltejs/kit 1.8.3 → 1.8.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.8.3",
3
+ "version": "1.8.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -16,7 +16,7 @@
16
16
  "devalue": "^4.3.0",
17
17
  "esm-env": "^1.0.0",
18
18
  "kleur": "^4.1.5",
19
- "magic-string": "^0.29.0",
19
+ "magic-string": "^0.30.0",
20
20
  "mime": "^3.0.0",
21
21
  "sade": "^1.8.1",
22
22
  "set-cookie-parser": "^2.5.1",
@@ -80,7 +80,7 @@
80
80
  "node": "^16.14 || >=18"
81
81
  },
82
82
  "scripts": {
83
- "lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore && eslint src/**/*.js",
83
+ "lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
84
84
  "check": "tsc",
85
85
  "check:all": "tsc && pnpm -r --filter=\"./**\" check",
86
86
  "format": "prettier --write . --config ../../.prettierrc --ignore-path .gitignore",
package/postinstall.js CHANGED
@@ -1,5 +1,5 @@
1
- import fs from 'fs';
2
- import path from 'path';
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
3
  import glob from 'tiny-glob/sync.js';
4
4
  import { load_config } from './src/core/config/index.js';
5
5
  import * as sync from './src/core/sync/sync.js';
@@ -82,7 +82,7 @@ export function create_builder({
82
82
  return;
83
83
  }
84
84
 
85
- const files = await glob('**/*.{html,js,json,css,svg,xml,wasm}', {
85
+ const files = await glob('**/*.{html,js,mjs,json,css,svg,xml,wasm}', {
86
86
  cwd: directory,
87
87
  dot: true,
88
88
  absolute: true,
@@ -138,6 +138,10 @@ const options = object(
138
138
 
139
139
  outDir: string('.svelte-kit'),
140
140
 
141
+ output: object({
142
+ preloadStrategy: list(['modulepreload', 'preload-js', 'preload-mjs'], 'modulepreload')
143
+ }),
144
+
141
145
  paths: object({
142
146
  base: validate('', (input, keypath) => {
143
147
  assert_string(input, keypath);
@@ -36,6 +36,7 @@ export const options = {
36
36
  embedded: ${config.kit.embedded},
37
37
  env_public_prefix: '${config.kit.env.publicPrefix}',
38
38
  hooks: null, // added lazily, via \`get_hooks\`
39
+ preload_strategy: ${s(config.kit.output.preloadStrategy)},
39
40
  root,
40
41
  service_worker: ${has_service_worker},
41
42
  templates: {
@@ -507,6 +507,9 @@ export function set_building() {
507
507
  }
508
508
  }
509
509
 
510
+ // see the kit.output.preloadStrategy option for details on why we have multiple options here
511
+ const ext = kit.output.preloadStrategy === 'preload-mjs' ? 'mjs' : 'js';
512
+
510
513
  new_config = {
511
514
  base: ssr ? assets_base(kit) : './',
512
515
  build: {
@@ -516,12 +519,8 @@ export function set_building() {
516
519
  input,
517
520
  output: {
518
521
  format: 'esm',
519
- // we use .mjs for client-side modules, because this signals to Chrome (when it
520
- // reads the <link rel="preload">) that it should parse the file as a module
521
- // rather than as a script, preventing a double parse. Ideally we'd just use
522
- // modulepreload, but Safari prevents that
523
- entryFileNames: ssr ? '[name].js' : `${prefix}/[name].[hash].mjs`,
524
- chunkFileNames: ssr ? 'chunks/[name].js' : `${prefix}/chunks/[name].[hash].mjs`,
522
+ entryFileNames: ssr ? '[name].js' : `${prefix}/[name].[hash].${ext}`,
523
+ chunkFileNames: ssr ? 'chunks/[name].js' : `${prefix}/chunks/[name].[hash].${ext}`,
525
524
  assetFileNames: `${prefix}/assets/[name].[hash][extname]`,
526
525
  hoistTransitiveImports: false
527
526
  },
@@ -273,12 +273,13 @@ export async function render_response({
273
273
  );
274
274
 
275
275
  for (const path of included_modulepreloads) {
276
- // we use modulepreload with the Link header for Chrome, along with
277
- // <link rel="preload"> for Safari. This results in the fastest loading in
278
- // the most used browsers, with no double-loading. Note that we need to use
279
- // .mjs extensions for `preload` to behave like `modulepreload` in Chrome
276
+ // see the kit.output.preloadStrategy option for details on why we have multiple options here
280
277
  link_header_preloads.add(`<${encodeURI(path)}>; rel="modulepreload"; nopush`);
281
- head += `\n\t\t<link rel="preload" as="script" crossorigin="anonymous" href="${path}">`;
278
+ if (options.preload_strategy !== 'modulepreload') {
279
+ head += `\n\t\t<link rel="preload" as="script" crossorigin="anonymous" href="${path}">`;
280
+ } else if (state.prerendering) {
281
+ head += `\n\t\t<link rel="modulepreload" href="${path}">`;
282
+ }
282
283
  }
283
284
 
284
285
  const blocks = [];
package/types/index.d.ts CHANGED
@@ -422,6 +422,20 @@ export interface KitConfig {
422
422
  * @default ".svelte-kit"
423
423
  */
424
424
  outDir?: string;
425
+ /**
426
+ * Options related to the build output format
427
+ */
428
+ output?: {
429
+ /**
430
+ * SvelteKit will preload the JavaScript modules needed for the initial page to avoid import 'waterfalls', resulting in faster application startup. There
431
+ * are three strategies with different trade-offs:
432
+ * - `modulepreload` - uses `<link rel="modulepreload">`. This delivers the best results in Chromium-based browsers, but is currently ignored by Firefox and Safari (though support is coming to Safari soon).
433
+ * - `preload-js` - uses `<link rel="preload">`. Prevents waterfalls in Chromium and Safari, but Chromium will parse each module twice (once as a script, once as a module). Causes modules to be requested twice in Firefox. This is a good setting if you want to maximise performance for users on iOS devices at the cost of a very slight degradation for Chromium users.
434
+ * - `preload-mjs` - uses `<link rel="preload">` but with the `.mjs` extension which prevents double-parsing in Chromium. Some static webservers will fail to serve .mjs files with a `Content-Type: application/javascript` header, which will cause your application to break. If that doesn't apply to you, this is the option that will deliver the best performance for the largest number of users, until `modulepreload` is more widely supported.
435
+ * @default "modulepreload"
436
+ */
437
+ preloadStrategy?: 'modulepreload' | 'preload-js' | 'preload-mjs';
438
+ };
425
439
  paths?: {
426
440
  /**
427
441
  * An absolute path that your app's files are served from. This is useful if your files are served from a storage bucket of some kind.
@@ -337,6 +337,7 @@ export interface SSROptions {
337
337
  embedded: boolean;
338
338
  env_public_prefix: string;
339
339
  hooks: ServerHooks;
340
+ preload_strategy: ValidatedConfig['kit']['output']['preloadStrategy'];
340
341
  root: SSRComponent['default'];
341
342
  service_worker: boolean;
342
343
  templates: {