From 23356a22c4b6e4931604f64ccd2acd8be6e2a055 Mon Sep 17 00:00:00 2001 From: Wituareard <87208350+Wituareard@users.noreply.github.com> Date: Sat, 5 Oct 2024 22:57:36 +0200 Subject: [PATCH 1/2] Load Google Analytics in web worker using Partytown --- .gitignore | 1 + package.json | 1 + pnpm-lock.yaml | 10 ++++ scripts/exclude-from-edge-function.ts | 2 +- src/app.html | 72 ++++++++++++++------------- src/routes/+layout.svelte | 10 ++++ vite.config.ts | 11 +++- 7 files changed, 70 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index 8b930ba6..7bd8fbf4 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ vite.config.ts.timestamp-* # Local Netlify folder .netlify /static/pagefind +/static/~partytown .env diff --git a/package.json b/package.json index ef396f2d..245dac87 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "vite": "^5.2.2" }, "dependencies": { + "@builder.io/partytown": "^0.10.2", "@fontsource/jetbrains-mono": "^4.5.12", "@fontsource/manrope": "^4.5.13", "@fontsource/roboto-slab": "^5.0.19", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4db9830b..2a3e70bc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: dependencies: + '@builder.io/partytown': + specifier: ^0.10.2 + version: 0.10.2 '@fontsource/jetbrains-mono': specifier: ^4.5.12 version: 4.5.12 @@ -149,6 +152,11 @@ packages: resolution: {integrity: sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==} engines: {node: '>=6.0.0'} + '@builder.io/partytown@0.10.2': + resolution: {integrity: sha512-A9U+4PREWcS+CCYzKGIPovtGB/PBgnH/8oQyCE6Nr9drDJk6cMPpLQIEajpGPmG9tYF7N3FkRvhXm/AS9+0iKg==} + engines: {node: '>=18.0.0'} + hasBin: true + '@esbuild/aix-ppc64@0.19.12': resolution: {integrity: sha512-bmoCYyWdEL3wDQIVbcyzRyeKLgk2WtWLTWz1ZIAZF/EGbNOwSA6ew3PftJ1PqMiOOGu0OyFMzG53L0zqIpPeNA==} engines: {node: '>=12'} @@ -2145,6 +2153,8 @@ snapshots: '@jridgewell/gen-mapping': 0.3.5 '@jridgewell/trace-mapping': 0.3.25 + '@builder.io/partytown@0.10.2': {} + '@esbuild/aix-ppc64@0.19.12': optional: true diff --git a/scripts/exclude-from-edge-function.ts b/scripts/exclude-from-edge-function.ts index f8b16963..d4c69476 100644 --- a/scripts/exclude-from-edge-function.ts +++ b/scripts/exclude-from-edge-function.ts @@ -1,7 +1,7 @@ import { promises as fs } from 'fs' const MANIFEST_PATH = '.netlify/edge-functions/manifest.json' -const EXCLUDE_PATHS = ['^/pagefind/.*$'] +const EXCLUDE_PATHS = ['^/pagefind/.*$', '^/~partytown/.*$'] const manifest = JSON.parse(await fs.readFile(MANIFEST_PATH, 'utf-8')) const renderFunction = manifest.functions.find( diff --git a/src/app.html b/src/app.html index e0123a1d..19b69c8f 100644 --- a/src/app.html +++ b/src/app.html @@ -1,38 +1,40 @@ - - - - - - - - - - - - - - %sveltekit.head% - - - -
%sveltekit.body%
- - + + + + + + + + + + + + + %sveltekit.head% + + + +
%sveltekit.body%
+ diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 613f014b..850af7d8 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,6 +1,7 @@ + + + {@html ''} + +

(Top)

diff --git a/vite.config.ts b/vite.config.ts index cf3748aa..a39180ed 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,10 +1,19 @@ +import { partytownVite } from '@builder.io/partytown/utils' +import { join } from 'path' import { sveltekit } from '@sveltejs/kit/vite' const config = { server: { port: 37572 }, - plugins: [sveltekit()] + plugins: [ + // Partytown first because SvelteKit copies /static in same hook + partytownVite({ + // Place in /static as /build is wiped by adapter which always runs last + dest: join(__dirname, 'static', '~partytown') + }), + sveltekit() + ] } export default config From 29ed90a6927ffdc36822196ca5a42bc113aceb3b Mon Sep 17 00:00:00 2001 From: Wituareard <87208350+Wituareard@users.noreply.github.com> Date: Sat, 5 Oct 2024 23:39:14 +0200 Subject: [PATCH 2/2] Add note about debugging with Partytown --- .vscode/ltex.dictionary.en-US.txt | 1 + README.md | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/.vscode/ltex.dictionary.en-US.txt b/.vscode/ltex.dictionary.en-US.txt index 86ffd283..cad09a8a 100644 --- a/.vscode/ltex.dictionary.en-US.txt +++ b/.vscode/ltex.dictionary.en-US.txt @@ -112,3 +112,4 @@ Roboto Saira impersonification Partiful +Partytown diff --git a/README.md b/README.md index 32857b94..c906549c 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,10 @@ pnpm run dev # Open http://localhost:37572 ``` +## Debugging + +The website uses the Partytown library, which can clutter network requests in DevTools with entries for `proxytown`. To exclude those requests, you can use the filter `-url:proxytown`. + ## Deployment The contents of the repository are continuously deployed to Netlify. You can track the deployment status [here](https://app.netlify.com/sites/pauseai/deploys).