mikemike mikemike -3 years ago 182
PHP Question

How can I change the public path to something containing an underscore in Laravel Mix?

In Laravel 5.4 Mix was introduced to compile assets and maintain the asset pipeline. Mix defaults to your public directory being named

. In many cases, including mine, my public directory is called something else. In my case, it's

How can I change the public directory where assets are compiled to?

I have tried changing the paths within

mix.js('resources/assets/js/app.js', 'public_html/assets/js')
.sass('resources/assets/sass/app.scss', 'public_html/assets/css');

Unfortunately this compiles to:

- public
|- _html
|-- assets
|--- css
|--- js
|- fonts

In Laravel 5.3 and Elixir this was as simple as:

elixir.config.publicPath = 'public_html/assets';

I have checked Mix's config file, but can't see anything obvious here.

Please note: this is Laravel Mix, the npm package, so it's nothing to do with amends in the

Answer Source

There is an undocumented (I believe) method called setPublicPath. You can then omit the public path from the output. setPublicPath plays nicely with underscores.

mix.js('resources/assets/js/app.js', 'assets/js')
   .sass('resources/assets/sass/app.scss', 'assets/css');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download