Environment:
Laravel Mix Version: 1.4.2
Node Version: 6.10.0
NPM Version: 3.10.10
OS: OS X
Description
Hi,
In older version 0.x there was no problem with this since the manifest file was generated in the main folder of output path (inside public folder), but in the latest version, the manifest file is always generated in public folder. For example:
Behaviour on 0.x
mix.js('resources/assets/js/app.js','public/build/js') --> manifest file is generated in /public/build/mix-manifest.js
Behaviour on 1.4.2
mix.js('resources/assets/js/app.js','public/build/js') --> manifest file is generated in /public/mix-manifest.js
My question is: Is there a way to set the path for manifest file? The idea is that I want to have 2 different manifest files, one for dev env and another for prod env.
Thank you.
@geodeveloper you can use the mix.setPublicPath() to set the path.
@zarkin404 thanks for the tip, I already tried this but doesn't work as expected, for example:
let mix = require('laravel-mix').setPublicPath('public/build');
mix.js('resources/assets/js/app.js','public/build/js')
it generates everything like this:
public/build/mix-manifest.json <-- this is ok
public/build/public/js/app.js` <-- generated files, this is not ok
... as you can see the generated files are generated into another public folder.
the expected behavior should be:
public/build/mix-manifest.json
public/build/js/app.js
Thanks.
@geodeveloper maybe you shold normalize the path like this: setPublicPath(path.normalize('public/build'))
@zarkin404 thanks for the reply and suggestion. I've tried but the result is the same. Note: I've updated my previous comment (I had a bad example, the problem is with the duplicatedpublic folder when using setPublicPath.
Thanks.
@zarkin404 I got it working, was my fault, I had to update also the mix.js('resources/assets/js/app.js','public/build/js'), that's why I have duplicate public, just removed the public and now works as expected.
Thanks for your help, closing this issue.
@geodeveloper yeah, because the output path of the mix.js() is based on the public path, and the default public path is /public, once you set the public via mix.setPublicPath('foo'), the assets output path will be '/foo/{the output path you specified}'.
IMO last longing option is to set path.public for whole application through provider. I found a cleaner solution here:
// app/Providers/AppServiceProvider.php
...
public function boot()
{
...
$this->app->bind('path.public', function() {
return base_path() . '/../sibling-directory';
});
...
}
...
/../sibling-directory part is relative to laravel directory.
You can prettify this one with some environment variable (set via .env) to make it machine-agnostic.
@geodeveloper you can use the mix.setPublicPath() to set the path.
where do you get this hidden options? I couldn't find it in the mix docs
@josegus it's on doc: https://laravel-mix.com/docs/5.0/faq
Have a great day.
Most helpful comment
@geodeveloper you can use the mix.setPublicPath() to set the path.