-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: introduce `<Style />` * add tests
- Loading branch information
Showing
23 changed files
with
178 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import { css } from 'hono/css' | ||
import { createRoute } from 'honox/factory' | ||
import Counter from '../islands/counter' | ||
|
||
const className = css` | ||
font-family: sans-serif; | ||
` | ||
|
||
export default createRoute((c) => { | ||
const name = c.req.query('name') ?? 'Hono' | ||
return c.render( | ||
<div> | ||
<div class={className}> | ||
<h1>Hello, {name}!</h1> | ||
<Counter /> | ||
</div>, | ||
{ | ||
title: name, | ||
} | ||
{ title: name } | ||
) | ||
}) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,16 @@ | ||
import build from '@hono/vite-cloudflare-pages' | ||
import pages from '@hono/vite-cloudflare-pages' | ||
import honox from 'honox/vite' | ||
import client from 'honox/vite/client' | ||
import { defineConfig } from 'vite' | ||
|
||
export default defineConfig(({ mode }) => { | ||
if (mode === 'client') { | ||
return { | ||
build: { | ||
rollupOptions: { | ||
input: ['./app/client.ts'], | ||
output: { | ||
entryFileNames: 'static/client.js', | ||
chunkFileNames: 'static/assets/[name]-[hash].js', | ||
assetFileNames: 'static/assets/[name].[ext]', | ||
}, | ||
}, | ||
emptyOutDir: false, | ||
copyPublicDir: false, | ||
}, | ||
plugins: [client()], | ||
} | ||
} else { | ||
return { | ||
plugins: [honox(), build()], | ||
plugins: [honox(), pages()], | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/server/components.tsx → src/server/components/has-islands.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { HasIslands } from './has-islands.js' | ||
export { Script } from './script.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { FC } from 'hono/jsx' | ||
import type { Manifest } from 'vite' | ||
|
||
type Options = { | ||
src: string | ||
prod?: boolean | ||
manifest?: Manifest | ||
} | ||
|
||
export const Script: FC<Options> = async (options) => { | ||
const src = options.src | ||
if (options.prod ?? import.meta.env.PROD) { | ||
let manifest: Manifest | undefined = options.manifest | ||
if (!manifest) { | ||
// @ts-expect-error not typed | ||
const manifestFile = await import('/dist/.vite/manifest.json') | ||
manifest = manifestFile['default'] | ||
} | ||
if (manifest) { | ||
const scriptInManifest = manifest[src.replace(/^\//, '')] | ||
if (scriptInManifest) { | ||
return <script type='module' src={`/${scriptInManifest.file}`}></script> | ||
} | ||
} | ||
return <></> | ||
} else { | ||
return <script type='module' src={src}></script> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { createApp } from './server.js' | ||
export type { ServerOptions } from './server.js' | ||
export { HasIslands } from './components.js' | ||
export * from './components/index.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { Plugin } from 'vite' | ||
|
||
type Options = { | ||
jsxImportSource?: string | ||
assetsDir?: string | ||
} | ||
|
||
export const defaultOptions: Options = { | ||
jsxImportSource: 'hono/jsx/dom', | ||
assetsDir: 'static', | ||
} | ||
|
||
function client(options?: Options): Plugin { | ||
return { | ||
name: 'honox-vite-client', | ||
config: () => { | ||
return { | ||
build: { | ||
rollupOptions: { | ||
input: ['/app/client.ts'], | ||
}, | ||
assetsDir: options?.assetsDir ?? defaultOptions.assetsDir, | ||
manifest: true, | ||
}, | ||
esbuild: { | ||
jsxImportSource: options?.jsxImportSource ?? defaultOptions.jsxImportSource, | ||
}, | ||
} | ||
}, | ||
} | ||
} | ||
|
||
export default client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Script } from '../../../../src/server' | ||
|
||
export default function Hello() { | ||
return ( | ||
<html> | ||
<head> | ||
<Script | ||
src='/app/client.ts' | ||
prod={true} | ||
manifest={{ | ||
'app/client.ts': { | ||
file: 'static/client-abc.js', | ||
}, | ||
}} | ||
/> | ||
</head> | ||
</html> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.