Skip to content

Commit

Permalink
fix: improve error message upon $ vite preview
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Dec 9, 2024
1 parent fc5a751 commit 2fa784e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 12 additions & 2 deletions packages/vike-node/src/plugin/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export { vikeNode, vikeNode as default }

import pc from '@brillout/picocolors'
import { globalStore } from '../runtime/globalStore.js'
import type { ConfigVikeNodePlugin } from '../types.js'
import { assertUsage } from '../utils/assert.js'
import { commonConfig } from './plugins/commonConfig.js'
import { devServerPlugin } from './plugins/devServerPlugin.js'
import { edgePlugin } from './plugins/edgePlugin.js'
Expand All @@ -12,11 +14,19 @@ globalStore.isDev = true

function vikeNode(config: ConfigVikeNodePlugin) {
return [
//
commonConfig(config),
serverEntryPlugin(),
devServerPlugin(),
standalonePlugin(),
edgePlugin()
edgePlugin(),
{
name: 'vike-node:forbid-vite-preview-command',
configurePreviewServer() {
assertUsage(
false,
`${pc.cyan('$ vite preview')} isn't supported: directly execute the server production entry (for example ${pc.cyan('$ node dist/server/index.mjs')}) instead.`
)
}
}
]
}
2 changes: 1 addition & 1 deletion packages/vike-node/src/utils/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ function assert(condition: unknown): asserts condition {

function assertUsage(condition: unknown, message: string): asserts condition {
if (condition) return
throw new Error(`[vike-node] wrong usage: ${message}`)
throw new Error(`[vike-node][Wrong Usage] ${message}`)
}

0 comments on commit 2fa784e

Please sign in to comment.