Skip to content

Commit

Permalink
add support for configurable runtimeDir to adapter-static
Browse files Browse the repository at this point in the history
  • Loading branch information
endigma committed Nov 14, 2024
1 parent 574fbd3 commit f0649cf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
12 changes: 6 additions & 6 deletions packages/adapter-static/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import ReactDOM from 'react-dom/server'
// in order to prepare the app as a single-page app, we have 2 create 2 additional files:
// - an index.js that imports the application and calls React.render. This file needs to be built by vite so it's passed with the includePaths option for an adapter
// - an index.html containing the static shell that wraps the application.
const adapter: Adapter = async ({ outDir }) => {
const adapter: Adapter = async ({ outDir, config: { runtimeDir } }) => {
// the first thing we need to do is pull out the rendered html file into the root of the outDir
await fs.copyFile(
path.join(outDir, 'assets', '$houdini', 'temp', 'spa-shell', 'index.html'),
path.join(outDir, 'assets', runtimeDir, 'temp', 'spa-shell', 'index.html'),
path.join(outDir, 'index.html')
)

try {
await fs.rmdir(path.join(outDir, 'assets', '$houdini'))
await fs.rmdir(path.join(outDir, 'assets', runtimeDir))
} catch {}
}

// make sure we include the app entry point in the bundle
adapter.includePaths = {
shell: '$houdini/temp/spa-shell/index.html',
}
adapter.includePaths = ({ config: { runtimeDir } }) => ({
shell: path.join(runtimeDir, 'temp', 'spa-shell', 'index.html'),
})

// we dont want any server artifacts to be generated
adapter.disableServer = true
Expand Down
17 changes: 12 additions & 5 deletions packages/houdini-react/src/plugin/vite.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {
PluginHooks,
fs,
isSecondaryBuild,
load_manifest,
path,
PluginHooks,
type ProjectManifest,
type RouterManifest,
routerConventions,
type RouterManifest,
} from 'houdini'
import React from 'react'
import { build, ConfigEnv, type BuildOptions, type Connect } from 'vite'
import { build, type BuildOptions, ConfigEnv, type Connect } from 'vite'

import { manifest, setManifest } from '.'

Expand Down Expand Up @@ -72,8 +72,15 @@ export default {
'entries/adapter': routerConventions.adapter_config_path(config),
}

if (env.command === 'build' && config.adapter && config.adapter?.includePaths) {
Object.assign(conf.build!.rollupOptions!.input, config.adapter?.includePaths)
if (env.command === 'build' && config.adapter && config.adapter.includePaths) {
if (typeof config.adapter?.includePaths === 'function') {
Object.assign(
conf.build!.rollupOptions!.input,
config.adapter.includePaths({ config })
)
} else {
Object.assign(conf.build!.rollupOptions!.input, config.adapter.includePaths)
}
}

// every page in the manifest is a new entry point for vite
Expand Down
2 changes: 1 addition & 1 deletion packages/houdini/src/lib/router/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type Adapter = ((args: {
manifest: ProjectManifest
adapterPath: string
}) => void | Promise<void>) & {
includePaths?: Record<string, string>
includePaths?: Record<string, string> | ((args: { config: Config }) => Record<string, string>)
disableServer?: boolean
pre?: (args: {
config: Config
Expand Down

0 comments on commit f0649cf

Please sign in to comment.