From c193c72b784ed7a7862a3f01e249eb25889224a6 Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Tue, 23 Jan 2024 23:28:04 +0900 Subject: [PATCH] fix(vite): simplify vite config --- examples/basic/app/server.ts | 5 +---- examples/basic/package.json | 1 + examples/basic/vite.config.ts | 11 ++--------- examples/mdx/vite.config.ts | 4 ++-- src/vite/index.ts | 17 ----------------- yarn.lock | 10 ++++++++++ 6 files changed, 16 insertions(+), 32 deletions(-) diff --git a/examples/basic/app/server.ts b/examples/basic/app/server.ts index e3d696e..c0cbcb7 100644 --- a/examples/basic/app/server.ts +++ b/examples/basic/app/server.ts @@ -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) diff --git a/examples/basic/package.json b/examples/basic/package.json index 6b0f6aa..a381564 100644 --- a/examples/basic/package.json +++ b/examples/basic/package.json @@ -13,6 +13,7 @@ "wrangler": "^3.23.0" }, "dependencies": { + "@hono/vite-cloudflare-pages": "^0.2.0", "honox": "workspace:^" } } diff --git a/examples/basic/vite.config.ts b/examples/basic/vite.config.ts index c11482c..288bda1 100644 --- a/examples/basic/vite.config.ts +++ b/examples/basic/vite.config.ts @@ -1,3 +1,4 @@ +import build from '@hono/vite-cloudflare-pages' import honox from 'honox/vite' import { defineConfig } from '../../node_modules/vite' @@ -19,15 +20,7 @@ export default defineConfig(({ mode }) => { } } else { return { - build: { - rollupOptions: { - output: { - entryFileNames: '_worker.js', - }, - }, - minify: true, - }, - plugins: [honox()], + plugins: [honox(), build()], } } }) diff --git a/examples/mdx/vite.config.ts b/examples/mdx/vite.config.ts index 688ba58..8e63701 100644 --- a/examples/mdx/vite.config.ts +++ b/examples/mdx/vite.config.ts @@ -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' @@ -11,7 +11,7 @@ const entry = './app/server.ts' export default defineConfig(() => { return { plugins: [ - islandComponents(), + honox(), devServer({ entry }), ssg({ entry }), mdx({ diff --git a/src/vite/index.ts b/src/vite/index.ts index f3f8510..925022a 100644 --- a/src/vite/index.ts +++ b/src/vite/index.ts @@ -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' @@ -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[] { @@ -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, ] diff --git a/yarn.lock b/yarn.lock index 33e1eab..60bf1ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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"