alphasolution's avatar

Laravel install in a subfolder. The compiled javascript and css with version() method can't load using mix function in blade.

Does anyone know the correct way to use the mix function if I install Laravel in a subfolder?

I added RewriteBase /subfolder/ in the public/.htaccess file which make my application work but the javascript and css file can't load. The response HTML files are link to the root directory. I don't know how to fix it?

0 likes
4 replies
jlrdw's avatar

Install laravel correctly, on this very forum right now there's a discussion happening, click that discussion.

alphasolution's avatar

Thanks jlrdw,

The problem I met is not about how to install Laravel under a subfolder. My problem is about the mix.version() doesn't work if I install Laravel under a subfolder and I can't see any discussion on that.

I installed Laravel correctly. My problem is the css and javascript file can't be loaded after I use mix to make file versioning.

I can fix my problem by modify the mix-manifest.json file. In the mix-manifest.json, I update the path with the correct folder and all css and javascript files can be loaded.

The original mix-manifest.json file

{
  "/js/app.js": "/js/app.dd5a205adeb24187ecd0.js",
  "/mix.js": "/mix.0a8c4e42d296116bbe72.js",
  "/css/app.css": "/css/app.a6d1964076dc3d2fdb9bbe7ff44ec36d.css"
}

The updated mix-manifest.json

{
  "/js/app.js": "/subfolder/js/app.dd5a205adeb24187ecd0.js",
  "/mix.js": "/subfolder/mix.0a8c4e42d296116bbe72.js",
  "/css/app.css": "/subfolder/css/app.a6d1964076dc3d2fdb9bbe7ff44ec36d.css"
}

Now, I want to know is there any option can be added to the webpack.mix.js so that I don't need to update the mix-manifest.json after I deploy my application.

1 like
richwilliamson's avatar

I realise this is a very old topic but did you ever get a solution for this? I'm having the exact same issue atm where I need to prepend a directory name to the right hand side of the output in the manifest file.

It seems like setPublicPath and setResourceRoot functions are more for moving files into directories which fails as I don't have the folder itself in my laravel project but I need the full path when I use mix() to output the file path for css/js assets. Manually editing the manifest works perfectly but obviously that's not a great solution going forward, I'd rather find a way to get mix.version() to prepend the path so it's handled when I run npm.

mauricio_aux's avatar

I've had this problem for 6 days and it seems that every time I try something new something else fails. How can an amazing tool like Laravel not have an easy way to implement it as a subdirectory

Please or to participate in this conversation.