Skip to content

Commit

Permalink
Provides hook to access dev url while transforming (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
timacdonald authored Feb 1, 2023
1 parent 6a5d766 commit b8ea8f4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ interface PluginConfig {
* @default false
*/
valetTls?: string|boolean,

/**
* Transform the code while serving.
*/
transformOnServe?: (code: string, url: DevServerUrl) => string,
}

interface RefreshConfig {
Expand Down Expand Up @@ -174,7 +179,9 @@ function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlug
},
transform(code) {
if (resolvedConfig.command === 'serve') {
return code.replace(/__laravel_vite_placeholder__/g, viteDevServerUrl)
code = code.replace(/__laravel_vite_placeholder__/g, viteDevServerUrl)

return pluginConfig.transformOnServe(code, viteDevServerUrl)
}
},
configureServer(server) {
Expand Down Expand Up @@ -325,6 +332,7 @@ function resolvePluginConfig(config: string|string[]|PluginConfig): Required<Plu
refresh: config.refresh ?? false,
hotFile: config.hotFile ?? path.join((config.publicDirectory ?? 'public'), 'hot'),
valetTls: config.valetTls ?? false,
transformOnServe: config.transformOnServe ?? ((code) => code),
}
}

Expand Down

0 comments on commit b8ea8f4

Please sign in to comment.