Skip to content

Commit

Permalink
fix #111 (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
PredokMiF authored Aug 5, 2023
1 parent 568e178 commit 7092ded
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/fastify-vite/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async function configure (options = {}) {
const defaultConfig = { ...DefaultConfig }
const root = resolveRoot(options.root)
const dev = typeof options.dev === 'boolean' ? options.dev : defaultConfig.dev
const [vite, viteConfig] = await resolveViteConfig(root, dev)
const [vite, viteConfig] = await resolveViteConfig(root, dev, options.spa)
const resolveBundle = options.spa ? resolveSPABundle : resolveSSRBundle
const bundle = await resolveBundle({ dev, vite })
const config = Object.assign(defaultConfig, {
Expand Down Expand Up @@ -155,20 +155,29 @@ function resolveRoot (root) {
}
}

async function resolveViteConfig (root, dev) {
async function resolveViteConfig (root, dev, isSpa) {
const command = 'serve'
const mode = dev ? 'development' : 'production'
for (const ext of ['js', 'mjs', 'ts']) {
let configFile = join(root, `vite.config.${ext}`)
if (exists(configFile)) {
const resolvedConfig = await resolveConfig({
configFile
}, 'serve', dev ? 'development' : 'production')
}, command, mode)
if (process.platform === 'win32') {
configFile = `file://${configFile}`
}
let userConfig = await import(configFile).then(m => m.default)
if (userConfig.default) {
userConfig = userConfig.default
}
if (typeof userConfig === 'function') {
userConfig = userConfig({
command,
mode,
ssrBuild: !isSpa,
})
}
return [
Object.assign(userConfig, {
build: {
Expand Down

0 comments on commit 7092ded

Please sign in to comment.