Skip to content

Commit

Permalink
feat: ✨compatible with vite-ssg
Browse files Browse the repository at this point in the history
  • Loading branch information
nailiable committed Oct 26, 2024
1 parent 1662f58 commit 27ecf64
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 37 deletions.
3 changes: 2 additions & 1 deletion backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export const app = new RpcBootstrap(new NodeHttpAdapter())

// It will be called when environment is production mode
if (import.meta.env.PROD)
app.run(1000)
// eslint-disable-next-line no-console
app.run(1000).then(() => console.log(`Server is running on http://localhost:1000 in ${app.getBaseURL()}`))
2 changes: 1 addition & 1 deletion frontend/utils/request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createRpcClient } from '@nailyjs/rpc/axios'

export function useRequest() {
return createRpcClient()
return createRpcClient(import.meta.env.PROD ? 'http://localhost:1000/rpc' : '/rpc')
}
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"lint": "eslint .",
"preview": "vite preview",
"preview-https": "serve dist",
"preview-server": "node ./dist/backend/main.js",
"test": "vitest",
"test:e2e": "cypress open",
"test:unit": "vitest",
Expand All @@ -17,9 +18,9 @@
"sizecheck": "npx vite-bundle-visualizer"
},
"dependencies": {
"@nailyjs/backend": "^1.0.7",
"@nailyjs/ioc": "^1.0.7",
"@nailyjs/rpc": "^1.0.7",
"@nailyjs/backend": "^1.0.13",
"@nailyjs/ioc": "^1.0.13",
"@nailyjs/rpc": "^1.0.13",
"@unhead/vue": "^1.10.0",
"@unocss/reset": "^0.62.2",
"@vueuse/core": "^11.0.1",
Expand Down Expand Up @@ -60,7 +61,7 @@
"typescript": "^5.5.4",
"unocss": "^0.62.2",
"unplugin-auto-import": "^0.18.2",
"unplugin-rpc": "^1.0.7",
"unplugin-rpc": "^1.0.13",
"unplugin-vue-components": "^0.27.4",
"unplugin-vue-macros": "^2.11.6",
"unplugin-vue-markdown": "^0.26.2",
Expand Down
56 changes: 29 additions & 27 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import Shiki from '@shikijs/markdown-it'
import WebfontDownload from 'vite-plugin-webfont-dl'
import VueRouter from 'unplugin-vue-router/vite'
import { VueRouterAutoImports } from 'unplugin-vue-router'
import Rpc from 'unplugin-rpc'
import Rpc from 'unplugin-rpc/vite'
import { buildServer } from 'unplugin-rpc'

export default defineConfig({
resolve: {
Expand All @@ -27,7 +28,9 @@ export default defineConfig({
},

plugins: [
Rpc.vite(),
Rpc({
buildOnViteCloseBundle: false,
}),

VueMacros({
plugins: {
Expand Down Expand Up @@ -167,8 +170,16 @@ export default defineConfig({
crittersOptions: {
reduceInlineStyles: false,
},
onFinished() {
generateSitemap()
entry: './frontend/main.ts',
async onFinished() {
await buildServer({
viteOptions: {
ssr: {
noExternal: [/^@nailyjs/],
},
},
})
generateSitemap({ outDir: './dist/frontend' })
},
},

Expand Down

0 comments on commit 27ecf64

Please sign in to comment.