Skip to content

Commit

Permalink
feat: add client plugin to honox/vite (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe authored Jun 16, 2024
1 parent 2d0a638 commit 903928f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/vite/client.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import type { Plugin } from 'vite'

type Options = {
export type ClientOptions = {
jsxImportSource?: string
assetsDir?: string
input?: string[]
}

export const defaultOptions: Options = {
export const defaultOptions: ClientOptions = {
jsxImportSource: 'hono/jsx/dom',
assetsDir: 'static',
input: [],
}

function client(options?: Options): Plugin {
function client(options?: ClientOptions): Plugin {
return {
name: 'honox-vite-client',
apply: (_config, { command, mode }) => {
if (command === 'build' && mode === 'client') {
return true
}
return false
},
config: () => {
const input = options?.input ?? defaultOptions.input ?? []
return {
build: {
rollupOptions: {
input: ['/app/client.ts'],
input: ['/app/client.ts', ...input],
},
assetsDir: options?.assetsDir ?? defaultOptions.assetsDir,
manifest: true,
Expand Down
4 changes: 4 additions & 0 deletions src/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import { injectImportingIslands } from './inject-importing-islands.js'
import { islandComponents } from './island-components.js'
import type { IslandComponentsOptions } from './island-components.js'
import { restartOnAddUnlink } from './restart-on-add-unlink.js'
import type { ClientOptions } from './client.js'
import client from './client.js'

type Options = {
islands?: boolean
entry?: string
devServer?: DevServerOptions
islandComponents?: IslandComponentsOptions
client?: ClientOptions
external?: string[]
}

Expand Down Expand Up @@ -44,6 +47,7 @@ function honox(options?: Options): PluginOption[] {

plugins.push(injectImportingIslands())
plugins.push(restartOnAddUnlink())
plugins.push(client(options?.client))

return [
{
Expand Down

0 comments on commit 903928f

Please sign in to comment.