Skip to content

Commit 3c93e12

Browse files
authored
Use Vite's envDir option if specified
Vite allows you to pass through a custom option for the envDir. This is useful in cases where you might have multiple frontend packages and so your vite.config.js is not in the root directory. This update checks for that config option and if so will use it over the current directory when resolving the APP_URL and laravel version.
1 parent aaffee1 commit 3c93e12

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ export default function laravel(config: string|string[]|PluginConfig): LaravelPl
124124
viteDevServerUrl = `${protocol}://${host}:${address.port}`
125125
fs.writeFileSync(hotFile, viteDevServerUrl)
126126

127-
const appUrl = loadEnv('', process.cwd(), 'APP_URL').APP_URL
127+
const envDir = resolvedConfig.envDir || process.cwd()
128+
const appUrl = loadEnv('', envDir, 'APP_URL').APP_URL
128129

129130
setTimeout(() => {
130-
server.config.logger.info(colors.red(`\n Laravel ${laravelVersion()} `))
131+
server.config.logger.info(colors.red(`\n Laravel ${laravelVersion(envDir)} `))
131132
server.config.logger.info(`\n > APP_URL: ` + colors.cyan(appUrl))
132133
})
133134
}
@@ -194,9 +195,9 @@ export default function laravel(config: string|string[]|PluginConfig): LaravelPl
194195
/**
195196
* The version of Laravel being run.
196197
*/
197-
function laravelVersion(): string {
198+
function laravelVersion(envDir?: string): string {
198199
try {
199-
const composer = JSON.parse(fs.readFileSync('composer.lock').toString())
200+
const composer = JSON.parse(fs.readFileSync(`${envDir}composer.lock`).toString())
200201

201202
return composer.packages?.find((composerPackage: {name: string}) => composerPackage.name === 'laravel/framework')?.version ?? ''
202203
} catch {

0 commit comments

Comments
 (0)