I have the exact same problem. I can get away with using the assets() helper, however if I need to use mix() helper for the cache busting it will failed as mentioned by OP.
Laravel Mix with public folder outside the project folder
Hi,
since a couple of days ago I worked with Elixir. Then I decided to “upgrade” to Mix in order to keep up with the new features of Laravel 5.4.
Currently I have a working solution but it’s far from perfect. My application setup is as follows:
- /project/ => project root folder (with the app, bootstrap, config folders)
- /public_html => the document root accessible from the web
I have chosen to move the public folder outside the project root because I’m using Laravel on a shared hosting and I wanted to keep the application scripts and framework code inaccessible from the web. This solution worked fine with Elixir and gulp but with Mix I got into troubles.
This is an excerpt from webpack.mix.js:
const { mix } = require('laravel-mix');
mix.setPublicPath('../public_html');
mix.styles([
'resources/assets/metronic/assets/global/plugins/font-awesome/css/font-awesome.css',
'resources/assets/metronic/assets/global/plugins/simple-line-icons/simple-line-icons.css',
'resources/assets/metronic/assets/global/plugins/bootstrap/css/bootstrap.css',
'resources/assets/metronic/assets/global/plugins/bootstrap-switch/css/bootstrap-switch.css',
], '../public_html/css/global-styles.css');
The mix.setPublicPath() is required to make sure the mix-manifest.json is saved in the right directory (otherwise the mix() helper will not be able to find the requested asset in the manifest).
The problem is that, with this kind of configuration, the mix-manifest.json file will contain something like this:
{
"../public_html/css/global-styles.css": "../public_html/css/global-styles.css"
}
The urls are “wrong” meaning that the mix() helper is unable to resolve them correctly whatever input path I give it (the function can’t find the asset or doesn’t return the correct URL due to the “../public_html” part).
Currently I overwritten the mix() helper to handle the situation (namely remove the ../public_html from the input path and output url) but I’m sure there’s should be a better way.
I tried to understand how Laravel Mix works reading it’s source code but it’s a bit beyond my current level of knowledge.
Is there anyone out there that had the same problem and was able to solve it without using strange ninja tricks?
Thanks!
Please or to participate in this conversation.