Skip to content

Commit

Permalink
Use routifyDir and build.outDir paths
Browse files Browse the repository at this point in the history
  • Loading branch information
yus-ham committed Jun 27, 2024
1 parent 5a5b08b commit c8f6af8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/extra/vite-plugin/typedef.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @prop {Boolean} run Run Routify
* @prop {Boolean} forceLogging Force logging in production
* @prop {VitePluginSpecificOptionsRender} render
* @prop {string} outDir
*/

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/extra/vite-plugin/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ export const optionsCheck = (options, isProduction) => {
*/
export const postSsrBuildProcess = async options => {
const type = options.render.ssr.type
fse.copySync(__dirname + `/assets/${type}Renderer.js`, 'dist/server/serve.js')
fse.copySync(__dirname + `/assets/${type}Renderer.js`, `${options.outDir}/server/serve.js`)

if (type === 'cjs') fse.writeFileSync('dist/server/package.json', '{}')
if (type === 'cjs') fse.writeFileSync(`${options.outDir}/server/package.json`, '{}')

fse.moveSync('dist/client/index.html', 'dist/server/index.html', { overwrite: true })
fse.moveSync(`${options.outDir}/client/index.html`, `${options.outDir}/server/index.html`, { overwrite: true })

if (options.render.ssg.enable) {
const spank = await getSpank()
await spank.start(options.render.ssg.spank)
}

if (!options.render.ssr.enable) {
fse.removeSync('dist/server')
fse.removeSync(`${options.outDir}/server`)
}
}

Expand Down
14 changes: 8 additions & 6 deletions lib/extra/vite-plugin/vite-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,22 @@ export default function RoutifyPlugin(input = {}) {
// cfg.ssr.noExternal = true
cfg.ssr.target = 'webworker'
}

options.routifyDir ||= './.routify'
options.outDir = cfg.build?.outDir || 'dist'

return {
appType:
cfg.appType || (options.render.ssr.enable ? 'custom' : undefined),
server: {
fs: {
strict: false,
allow: ['./.routify'],
allow: [options.routifyDir],
},
},
build: {
ssr: cfg.build?.ssr === true ? '.routify/render.js' : cfg.build?.ssr,
outDir:
cfg.build?.outDir ||
(cfg.build?.ssr ? 'dist/server' : 'dist/client'),
ssr: cfg.build?.ssr === true ? `${options.routifyDir}/render.js` : cfg.build?.ssr,
outDir: `${options.outDir}/${cfg.build?.ssr ? 'server' : 'client'}`,
},
envPrefix: ['VITE_', 'ROUTIFY_SSR_ENABLE'],
}
Expand All @@ -73,7 +75,7 @@ export default function RoutifyPlugin(input = {}) {
closeBundle: async () => {
if (options.render.ssg.enable || options.render.ssr.enable) {
// build again, this time in the dist/server dir
if (!isSsr) await build({ build: { ssr: true } })
if (!isSsr) await build({ build: { ssr: true, outDir: options.outDir } })
else await postSsrBuildProcess(options)
}
},
Expand Down
1 change: 1 addition & 0 deletions typings/lib/extra/vite-plugin/typedef.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type VitePluginSpecificOptions = {
*/
forceLogging: boolean;
render: VitePluginSpecificOptionsRender;
outDir: string;
};
type VitePluginSpecificOptionsInput = {
/**
Expand Down

0 comments on commit c8f6af8

Please sign in to comment.