From 45bdca1982c45488e9c2cc377721650600e0f935 Mon Sep 17 00:00:00 2001 From: Katsuhiro Ueno Date: Sat, 20 Jul 2024 14:08:05 +0900 Subject: [PATCH] update example/multilib --- example/multilib/index.html.js | 2 +- example/multilib/vite.config.js | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/example/multilib/index.html.js b/example/multilib/index.html.js index c4d68e6..5c39162 100644 --- a/example/multilib/index.html.js +++ b/example/multilib/index.html.js @@ -12,7 +12,7 @@ export const main = () => ({ main: () => import('../../template/react/src/browser.html.jsx?render') }, 'solid/index.html': { - main: () => import('../../template/solid/src/index.html.jsx?render') + main: () => import('../../template/solid/src/index.html.jsx?hydrate&render') }, 'solid/browser.html': { main: () => import('../../template/solid/src/browser.html.jsx?render') diff --git a/example/multilib/vite.config.js b/example/multilib/vite.config.js index 070dd1d..5486747 100644 --- a/example/multilib/vite.config.js +++ b/example/multilib/vite.config.js @@ -12,11 +12,22 @@ import ssgSvelte from '@minissg/render-svelte' import ssgVue from '@minissg/render-vue' const preactPlugin = () => { + const include = /\/preact\/.*\.jsx(?:\?|$)/ return [ - preact({ include: [/\/preact\/.*\.jsx(?:\?|$)/] }), { - name: 'cancel-preact-alias', + enforce: 'pre', + name: 'preact-import-source', + transform(code, id) { + if (include.test(id)) return '// @jsxImportSource preact\n' + code + } + }, + preact({ include: [include] }), + { + name: 'manipulate-preact-config', config(c) { + if (c.esbuild.jsxImportSource === 'preact') { + delete c.esbuild.jsxImportSource + } c.resolve.alias = c.resolve.alias.filter( i => typeof i.replacement !== 'string' || @@ -28,22 +39,16 @@ const preactPlugin = () => { } const reactPlugin = () => { - return react({ include: [/\/react\/.*\.jsx(?:\?|$)/] }) + return [react({ include: [/\/react\/.*\.jsx(?:\?|$)/] })] } const solidPlugin = () => { return [ solid({ include: [/\/solid\/[^?]*\.jsx(?:\?|$)/], + extensions: ['.jsx'], ssr: true - }), - { - name: 'cancel-solid-include', - config(c) { - delete c.esbuild.include - c.esbuild.exclude = [/\/solid\/.*\.jsx(?:\?|$)/] - } - } + }) ] }