Skip to content

Commit

Permalink
fix(vite): simplify vite config (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe authored Jan 23, 2024
1 parent f38f8b4 commit 4579692
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 32 deletions.
5 changes: 1 addition & 4 deletions examples/basic/app/server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { serveStatic } from 'hono/cloudflare-pages'
import { showRoutes } from 'hono/dev'
import { createApp } from 'honox/server'

const app = createApp({
init: (app) => app.get('/static/*', serveStatic()),
})
const app = createApp()

showRoutes(app)

Expand Down
1 change: 1 addition & 0 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"wrangler": "^3.23.0"
},
"dependencies": {
"@hono/vite-cloudflare-pages": "^0.2.0",
"honox": "workspace:^"
}
}
11 changes: 2 additions & 9 deletions examples/basic/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import build from '@hono/vite-cloudflare-pages'
import honox from 'honox/vite'
import { defineConfig } from '../../node_modules/vite'

Expand All @@ -19,15 +20,7 @@ export default defineConfig(({ mode }) => {
}
} else {
return {
build: {
rollupOptions: {
output: {
entryFileNames: '_worker.js',
},
},
minify: true,
},
plugins: [honox()],
plugins: [honox(), build()],
}
}
})
4 changes: 2 additions & 2 deletions examples/mdx/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import devServer from '@hono/vite-dev-server'
import mdx from '@mdx-js/rollup'
import { islandComponents } from 'honox/vite'
import honox from 'honox/vite'
import remarkFrontmatter from 'remark-frontmatter'
import remarkMdxFrontmatter from 'remark-mdx-frontmatter'
import { defineConfig } from '../../node_modules/vite'
Expand All @@ -11,7 +11,7 @@ const entry = './app/server.ts'
export default defineConfig(() => {
return {
plugins: [
islandComponents(),
honox(),
devServer({ entry }),
ssg({ entry }),
mdx({
Expand Down
17 changes: 0 additions & 17 deletions src/vite/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { builtinModules } from 'module'
import path from 'path'
import devServer, { defaultOptions as devServerDefaultOptions } from '@hono/vite-dev-server'
import type { DevServerOptions } from '@hono/vite-dev-server'
Expand All @@ -15,7 +14,6 @@ type HonoXOptions = {
export const defaultOptions: HonoXOptions = {
islands: true,
entry: path.join(process.cwd(), './app/server.ts'),
external: ['react', 'react-dom'],
}

function honox(options?: HonoXOptions): PluginOption[] {
Expand Down Expand Up @@ -43,21 +41,6 @@ function honox(options?: HonoXOptions): PluginOption[] {
return [
{
name: 'honox-vite-config',
config: () => {
return {
ssr: {
noExternal: true,
external: defaultOptions.external,
},
build: {
ssr: entry,
rollupOptions: {
external: [...builtinModules, /^node:/],
input: entry,
},
},
}
},
},
...plugins,
]
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,15 @@ __metadata:
languageName: node
linkType: hard

"@hono/vite-cloudflare-pages@npm:^0.2.0":
version: 0.2.0
resolution: "@hono/vite-cloudflare-pages@npm:0.2.0"
peerDependencies:
hono: ">=3.11.7"
checksum: d7e228abea936cc11de454216a3c0941d2177e69cf2083bf5c2e56ac415cc7b3b806a4d0638b73a1b27a7ca3fae587c396337f8c70c4602e8646057448898c36
languageName: node
linkType: hard

"@hono/vite-dev-server@npm:^0.3.5":
version: 0.3.5
resolution: "@hono/vite-dev-server@npm:0.3.5"
Expand Down Expand Up @@ -1590,6 +1599,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "basic@workspace:examples/basic"
dependencies:
"@hono/vite-cloudflare-pages": "npm:^0.2.0"
honox: "workspace:^"
vite: "npm:^5.0.12"
wrangler: "npm:^3.23.0"
Expand Down

0 comments on commit 4579692

Please sign in to comment.