From d7404a8ef01de8e12747ad580495817656839c6c Mon Sep 17 00:00:00 2001 From: Fabian Hiller Date: Mon, 26 Feb 2024 02:14:39 -0500 Subject: [PATCH] Improve iframe implementation in playground --- library/tsup.config.ts | 28 +++++++++++---- website/netlify.toml | 12 +++++-- website/src/routes/playground/index.tsx | 48 +++++++++++++------------ 3 files changed, 57 insertions(+), 31 deletions(-) diff --git a/library/tsup.config.ts b/library/tsup.config.ts index 773544d2b..5861d0438 100644 --- a/library/tsup.config.ts +++ b/library/tsup.config.ts @@ -1,9 +1,23 @@ import { defineConfig } from 'tsup'; -export default defineConfig({ - entry: ['./src/index.ts'], - clean: true, - format: ['esm', 'cjs'], - dts: true, - outDir: './dist', -}); +export default defineConfig([ + { + entry: ['./src/index.ts'], + clean: true, + format: ['esm', 'cjs'], + minify: false, + dts: true, + outDir: './dist', + }, + { + entry: ['./src/index.ts'], + clean: true, + format: ['esm', 'cjs'], + minify: true, + dts: false, + outDir: './dist', + outExtension: ({ format }) => ({ + js: format === 'cjs' ? '.min.cjs' : '.min.js', + }), + }, +]); diff --git a/website/netlify.toml b/website/netlify.toml index 8d0152ad8..59209cd22 100644 --- a/website/netlify.toml +++ b/website/netlify.toml @@ -1,3 +1,11 @@ +# Netlify build config [build] -publish = "dist" -command = "cd ../library && npm run build && cd ../website && npm run sitemap && npm run build" + publish = "dist" + command = "cd ../library && npm run build && cd ../website && npm run sitemap && npm run build" + +# Netlify headers config +[[headers]] + # This is a temporary solution to be able to load the Valibot library into the playground iframe + for = "/build/*" + [headers.values] + access-control-allow-origin = "*" \ No newline at end of file diff --git a/website/src/routes/playground/index.tsx b/website/src/routes/playground/index.tsx index b04f269c0..bea35cfbd 100644 --- a/website/src/routes/playground/index.tsx +++ b/website/src/routes/playground/index.tsx @@ -25,7 +25,7 @@ import { import { useResetSignal } from '~/hooks'; import { BinIcon, CheckIcon, CopyIcon, PlayIcon, ShareIcon } from '~/icons'; import { trackEvent } from '~/utils'; -import valibotCode from '../../../../library/dist/index.js?url'; +import valibotCode from '../../../../library/dist/index.min.js?url'; export const head: DocumentHead = { title: 'Playground', @@ -56,7 +56,7 @@ export default component$(() => { const code = useSignal(''); const logs = useSignal<[LogLevel, string][]>([]); - // Capture logs from the iFrame + // Capture logs from iframe // eslint-disable-next-line qwik/no-use-visible-task useVisibleTask$(() => { window.addEventListener( @@ -64,10 +64,6 @@ export default component$(() => { (event: MessageEvent) => { // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (event.data.type === 'logs') { - // Log it to console - console[event.data.level](...event.data.args); - - // Add log to current logs logs.value = [ ...logs.value, [ @@ -137,12 +133,14 @@ console.log(result);`;
  •                  
                       {level}
                     
    @@ -156,23 +154,29 @@ console.log(result);`;
           {code.value && (