From acaaf364c445a84b3c6ba427495e73a946106207 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Wed, 26 Apr 2023 23:32:39 -0400 Subject: [PATCH] Use vite-plugin-iso-import to fix leaflet async imports --- web-frontend/package.json | 1 + web-frontend/src/lib/Map.svelte | 7 +++---- web-frontend/vite.config.js | 5 ++++- web-frontend/yarn.lock | 13 +++++++++++++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/web-frontend/package.json b/web-frontend/package.json index 7935f22..e50b53d 100644 --- a/web-frontend/package.json +++ b/web-frontend/package.json @@ -31,6 +31,7 @@ "tailwindcss": "^3.2.7", "typescript": "^4.9.3", "vite": "^4.1.4", + "vite-plugin-iso-import": "^1.0.0", "vite-plugin-pwa": "^0.14.6", "vite-plugin-wasm-pack": "^0.1.12" }, diff --git a/web-frontend/src/lib/Map.svelte b/web-frontend/src/lib/Map.svelte index 12adbde..571c8ce 100644 --- a/web-frontend/src/lib/Map.svelte +++ b/web-frontend/src/lib/Map.svelte @@ -2,6 +2,8 @@ import { onMount, onDestroy } from 'svelte'; import { browser } from '$app/environment'; import { createEventDispatcher } from 'svelte'; + import * as leaflet from 'leaflet?client'; + import * as leafletControlGeocoder from 'leaflet-control-geocoder?client'; const dispatch = createEventDispatcher(); @@ -35,11 +37,8 @@ } }; - onMount(async () => { + onMount(() => { if (browser) { - const leaflet = await import('leaflet'); - const leafletControlGeocoder = await import('leaflet-control-geocoder'); - map = leaflet.map(mapElement); // TODO: Pick a better spot map.setView([51.505, -0.09], 13); diff --git a/web-frontend/vite.config.js b/web-frontend/vite.config.js index 9dd1eec..9101491 100644 --- a/web-frontend/vite.config.js +++ b/web-frontend/vite.config.js @@ -2,6 +2,7 @@ import { sveltekit } from '@sveltejs/kit/vite'; import { SvelteKitPWA } from '@vite-pwa/sveltekit'; import wasmPack from 'vite-plugin-wasm-pack'; import { defineConfig } from 'vite'; +import { isoImport } from 'vite-plugin-iso-import'; export default defineConfig({ plugins: [sveltekit(), wasmPack('../xpin-wasm/'), SvelteKitPWA({ @@ -11,5 +12,7 @@ export default defineConfig({ devOptions: { enabled: true, }, - })] + }), + isoImport(), + ] }); diff --git a/web-frontend/yarn.lock b/web-frontend/yarn.lock index b89c72a..20429e7 100644 --- a/web-frontend/yarn.lock +++ b/web-frontend/yarn.lock @@ -2094,6 +2094,11 @@ es-abstract@^1.19.0, es-abstract@^1.20.4: unbox-primitive "^1.0.2" which-typed-array "^1.1.9" +es-module-lexer@^1.1.0: + version "1.2.1" + resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-1.2.1.tgz#ba303831f63e6a394983fde2f97ad77b22324527" + integrity sha512-9978wrXM50Y4rTMmW5kXIC09ZdXQZqkE4mxhwkd8VbzsGkXGPgV4zWuqQJgCEzYngdo2dYDa0l8xhX4fkSwJSg== + es-set-tostringtag@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/es-set-tostringtag/-/es-set-tostringtag-2.0.1.tgz#338d502f6f674301d710b80c8592de8a15f09cd8" @@ -4689,6 +4694,14 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" +vite-plugin-iso-import@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/vite-plugin-iso-import/-/vite-plugin-iso-import-1.0.0.tgz#71d83047d8dc77327278b56bff9e1e362edffbce" + integrity sha512-DqhCElHfkbkqLXtm0UMiAXqh9FdqRHegHpawXtp5LWHjGsdAqYPhmUGBTKFuTRwPSNFYCpyjHRsm7lvM2dskGw== + dependencies: + es-module-lexer "^1.1.0" + magic-string "^0.27.0" + vite-plugin-pwa@^0.14.6: version "0.14.6" resolved "https://registry.yarnpkg.com/vite-plugin-pwa/-/vite-plugin-pwa-0.14.6.tgz#71d77a9e39a3b3ccc265aa5e4d920d1fdd661461"