•
19 min read
Inline CSS from file
Build files
We usually access vite files from the blade directive
But if you need to inline content build files from Vite you can use the Vite
facade to get the built asset path and extract the contents. Let’s create a helper function to get the contents of a built file from the public path.
Which can now be used in your views.
Note: we only do this in production as the build file will not be present in development mode.
You could even wrap this up into a blade directive:
Existing files
You could also create a similar helper function to get the contents of a file from the resources directory if no build is required:
Note: We report exceptions and then continue in live systemss
Direct file include
You could also include the file directly and avoid any custom functions or build steps.