Skip to content

Commit

Permalink
[0.5.x] Support customising hot file / build path (#118)
Browse files Browse the repository at this point in the history
* support customising hot file

* add default value
  • Loading branch information
timacdonald authored Aug 25, 2022
1 parent 212faab commit 8324ce3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ interface PluginConfig {
*/
buildDirectory?: string

/**
* The path to the "hot" file.
*
* @default `${publicDirectory}/hot`
*/
hotFile?: string

/**
* The path of the SSR entry point.
*/
Expand Down Expand Up @@ -144,8 +151,6 @@ function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlug
}
},
configureServer(server) {
const hotFile = path.join(pluginConfig.publicDirectory, 'hot')

const envDir = resolvedConfig.envDir || process.cwd()
const appUrl = loadEnv(resolvedConfig.mode, envDir, 'APP_URL').APP_URL ?? 'undefined'

Expand All @@ -155,7 +160,7 @@ function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlug
const isAddressInfo = (x: string|AddressInfo|null|undefined): x is AddressInfo => typeof x === 'object'
if (isAddressInfo(address)) {
viteDevServerUrl = resolveDevServerUrl(address, server.config)
fs.writeFileSync(hotFile, viteDevServerUrl)
fs.writeFileSync(pluginConfig.hotFile, viteDevServerUrl)

setTimeout(() => {
server.config.logger.info(`\n ${colors.red(`${colors.bold('LARAVEL')} ${laravelVersion()}`)} ${colors.dim('plugin')} ${colors.bold(`v${pluginVersion()}`)}`)
Expand All @@ -170,8 +175,8 @@ function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlug
}

const clean = () => {
if (fs.existsSync(hotFile)) {
fs.rmSync(hotFile)
if (fs.existsSync(pluginConfig.hotFile)) {
fs.rmSync(pluginConfig.hotFile)
}
}

Expand Down Expand Up @@ -268,6 +273,7 @@ function resolvePluginConfig(config: string|string[]|PluginConfig): Required<Plu
ssr: config.ssr ?? config.input,
ssrOutputDirectory: config.ssrOutputDirectory ?? 'bootstrap/ssr',
refresh: config.refresh ?? false,
hotFile: config.hotFile ?? path.join((config.publicDirectory ?? 'public'), 'hot')
}
}

Expand Down

0 comments on commit 8324ce3

Please sign in to comment.