Skip to content

Commit

Permalink
fix: set build.outDir only if necessary (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Nov 15, 2022
1 parent d7c8d95 commit db069d2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
16 changes: 6 additions & 10 deletions telefunc/node/vite/plugins/buildConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,21 @@ function buildConfig(): Plugin {
name: 'telefunc:buildConfig',
apply: 'build',
config: (config) => {
const outDir = determineOutDir(config)
if (!config.build?.ssr) {
return {
build: {
outDir
}
}
} else {
if (config.build?.ssr) {
const input = {
[telefuncFilesGlobFileNameBase]: telefuncFilesGlobFilePath,
...normalizeRollupInput(config.build?.rollupOptions?.input)
}
return {
build: {
rollupOptions: { input },
outDir
rollupOptions: { input }
}
}
}
},
configResolved(config) {
const outDir = determineOutDir(config)
if (outDir) config.build.outDir = outDir
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions telefunc/node/vite/plugins/previewConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ function previewConfig(): Plugin {
return {
name: 'vite-plugin-ssr:previewConfig',
apply: apply('preview'),
config(config) {
const outDir = determineOutDir(config)
return {
build: { outDir }
}
},
configResolved(config_) {
config = config_
const outDir = determineOutDir(config) ?? undefined
if (outDir) config.build.outDir = outDir
},
configurePreviewServer(server) {
return () => {
Expand Down
9 changes: 5 additions & 4 deletions telefunc/utils/getOutDirs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ function getOutDirs(config: ResolvedConfig): OutDirs {
}

/** Appends `client/` or `server/` to `config.build.outDir` */
function determineOutDir(config: UserConfig): string {
const outDirRoot = toPosixPath(config.build?.outDir || 'dist')
function determineOutDir(config: ResolvedConfig): string | null {
const outDirRoot = toPosixPath(config.build.outDir)
console.log(config.build?.outDir, config.build?.ssr)
assertPosixPath(outDirRoot)
// When using Telefunc + vite-plugin-ssr then `config.build.outDir` may already be set
// When using vite-plugin-ssr and SvelteKit then `config.build.outDir` is already set
if (!isOutDirRoot(outDirRoot)) {
assertConfig(config)
return outDirRoot
return null
}
const { outDirClient, outDirServer } = declineOutDirs(outDirRoot)
if (viteIsSSR(config)) {
Expand Down

0 comments on commit db069d2

Please sign in to comment.