Skip to content

Commit

Permalink
feat(config): use defineConfig to set default
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Jan 4, 2025
1 parent 1965cd9 commit c67c353
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/vite",
"version": "5.2.0",
"version": "5.3.0",
"description": "Vite plugin for Athenna Framework.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down
14 changes: 10 additions & 4 deletions src/fastify/FastifyVite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* @credit https://github.com/adonisjs/vite
*/

/* eslint-disable @typescript-eslint/ban-ts-comment */

import path from 'node:path'
import fastifyPlugin from 'fastify-plugin'
import fastifyMiddie from '@fastify/middie'
Expand All @@ -21,10 +23,10 @@ import { View } from '@athenna/view'
import { Vite } from '#src/vite/Vite'
import { EdgeError } from 'edge-error'
import { Config } from '@athenna/config'
import type { ViteDevServer } from 'vite'
import type { FastifyInstance } from 'fastify'
import { Path, Options } from '@athenna/common'
import type { FastifyViteOptions } from '#src/types'
import { mergeConfig, type ViteDevServer } from 'vite'

export class FastifyVite {
public scope: FastifyInstance
Expand Down Expand Up @@ -61,17 +63,20 @@ export class FastifyVite {
* Don't start vite server under production.
*/
if (this.options.dev) {
const { createServer, loadConfigFromFile } = await import('vite')
const { mergeConfig, defineConfig, createServer, loadConfigFromFile } =
await import('vite')

const defaultConfig = {
const defaultConfig = defineConfig({
// @ts-ignore
configFile: false,
server: {
middlewareMode: true,
hmr: {
server: this.scope.server
}
},
appType: 'custom'
}
})

const { config } = await loadConfigFromFile(
{
Expand All @@ -82,6 +87,7 @@ export class FastifyVite {
this.options.root
)

// @ts-ignore
this.devServer = await createServer(mergeConfig(defaultConfig, config))

await this.scope.register(fastifyMiddie, { hook: 'onRequest' })
Expand Down

0 comments on commit c67c353

Please sign in to comment.