Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use routifyDir and build.outDir paths #557

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading