@@ -2,7 +2,7 @@ import fs from 'fs'
22import { AddressInfo } from 'net'
33import path from 'path'
44import colors from 'picocolors'
5- import { Plugin , loadEnv , UserConfig , ConfigEnv , Manifest , ResolvedConfig , SSROptions , normalizePath , PluginOption } from 'vite'
5+ import { Plugin , loadEnv , UserConfig , ConfigEnv , ResolvedConfig , SSROptions , PluginOption } from 'vite'
66import fullReload , { Config as FullReloadConfig } from 'vite-plugin-full-reload'
77
88interface PluginConfig {
@@ -85,7 +85,6 @@ export default function laravel(config: string|string[]|PluginConfig): [LaravelP
8585function resolveLaravelPlugin ( pluginConfig : Required < PluginConfig > ) : LaravelPlugin {
8686 let viteDevServerUrl : DevServerUrl
8787 let resolvedConfig : ResolvedConfig
88- const cssManifest : Manifest = { }
8988
9089 const defaultAliases : Record < string , string > = {
9190 '@' : '/resources/js' ,
@@ -159,9 +158,10 @@ function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlug
159158 fs . writeFileSync ( hotFile , viteDevServerUrl )
160159
161160 setTimeout ( ( ) => {
162- server . config . logger . info ( colors . red ( `\n Laravel ${ laravelVersion ( ) } ` ) )
163- server . config . logger . info ( `\n > APP_URL: ` + colors . cyan ( appUrl ) )
164- } )
161+ server . config . logger . info ( `\n ${ colors . red ( `${ colors . bold ( 'LARAVEL' ) } ${ laravelVersion ( ) } ` ) } ${ colors . dim ( 'plugin' ) } ${ colors . bold ( `v${ pluginVersion ( ) } ` ) } ` )
162+ server . config . logger . info ( '' )
163+ server . config . logger . info ( ` ${ colors . green ( '➜' ) } ${ colors . bold ( 'APP_URL' ) } : ${ colors . cyan ( appUrl . replace ( / : ( \d + ) / , ( _ , port ) => `:${ colors . bold ( port ) } ` ) ) } ` )
164+ } , 100 )
165165 }
166166 } )
167167
@@ -199,50 +199,6 @@ function resolveLaravelPlugin(pluginConfig: Required<PluginConfig>): LaravelPlug
199199
200200 next ( )
201201 } )
202- } ,
203-
204- // The following two hooks are a workaround to help solve a "flash of unstyled content" with Blade.
205- // They add any CSS entry points into the manifest because Vite does not currently do this.
206- renderChunk ( _ , chunk ) {
207- const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)`
208- const cssLangRE = new RegExp ( cssLangs )
209-
210- if ( ! chunk . isEntry || chunk . facadeModuleId === null || ! cssLangRE . test ( chunk . facadeModuleId ) ) {
211- return null
212- }
213-
214- const relativeChunkPath = normalizePath ( path . relative ( resolvedConfig . root , chunk . facadeModuleId ) )
215-
216- cssManifest [ relativeChunkPath ] = {
217- /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
218- /* @ts -ignore */
219- file : Array . from ( chunk . viteMetadata . importedCss ) [ 0 ] ?? chunk . fileName ,
220- src : relativeChunkPath ,
221- isEntry : true ,
222- }
223-
224- return null
225- } ,
226- writeBundle ( ) {
227- const manifestConfig = resolveManifestConfig ( resolvedConfig )
228-
229- if ( manifestConfig === false ) {
230- return ;
231- }
232-
233- const manifestPath = path . resolve ( resolvedConfig . root , resolvedConfig . build . outDir , manifestConfig )
234-
235- if ( ! fs . existsSync ( manifestPath ) ) {
236- // The manifest does not exist yet when first writing the legacy asset bundle.
237- return ;
238- }
239-
240- const manifest = JSON . parse ( fs . readFileSync ( manifestPath ) . toString ( ) )
241- const newManifest = {
242- ...manifest ,
243- ...cssManifest ,
244- }
245- fs . writeFileSync ( manifestPath , JSON . stringify ( newManifest , null , 2 ) )
246202 }
247203 }
248204}
@@ -260,6 +216,17 @@ function laravelVersion(): string {
260216 }
261217}
262218
219+ /**
220+ * The version of the Laravel Vite plugin being run.
221+ */
222+ function pluginVersion ( ) : string {
223+ try {
224+ return JSON . parse ( fs . readFileSync ( path . join ( __dirname , '../package.json' ) ) . toString ( ) ) ?. version
225+ } catch {
226+ return ''
227+ }
228+ }
229+
263230/**
264231 * Convert the users configuration into a standard structure with defaults.
265232 */
@@ -339,26 +306,6 @@ function resolveOutDir(config: Required<PluginConfig>, ssr: boolean): string|und
339306 return path . join ( config . publicDirectory , config . buildDirectory )
340307}
341308
342- /**
343- * Resolve the Vite manifest config from the configuration.
344- */
345- function resolveManifestConfig ( config : ResolvedConfig ) : string | false
346- {
347- const manifestConfig = config . build . ssr
348- ? config . build . ssrManifest
349- : config . build . manifest ;
350-
351- if ( manifestConfig === false ) {
352- return false
353- }
354-
355- if ( manifestConfig === true ) {
356- return config . build . ssr ? 'ssr-manifest.json' : 'manifest.json'
357- }
358-
359- return manifestConfig
360- }
361-
362309function resolveFullReloadConfig ( { refresh : config } : Required < PluginConfig > ) : PluginOption [ ] {
363310 if ( typeof config === 'boolean' ) {
364311 return [ ] ;
@@ -413,7 +360,7 @@ function noExternalInertiaHelpers(config: UserConfig): true|Array<string|RegExp>
413360 /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
414361 /* @ts -ignore */
415362 const userNoExternal = ( config . ssr as SSROptions | undefined ) ?. noExternal
416- const pluginNoExternal = [ 'laravel-vite-plugin' ]
363+ const pluginNoExternal = [ 'laravel-vite-plugin/inertia-helpers ' ]
417364
418365 if ( userNoExternal === true ) {
419366 return true
0 commit comments