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

Laravel 5.4 introduced a mixture to compile assets and maintain an asset pipeline. Mix the defaults with the public directory. In many cases, including mine, my shared directory is called something else. In my case, this is public_html .

How to change the shared directory in which assets are compiled?

I tried changing the paths in webpack.min.js to:

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

Unfortunately, this compiled:

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

In Laravel 5.3 and Elixir, it was as simple as:

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

I checked the Mix configuration file, but don't see anything obvious here.

Please note: this is Laravel Mix, the npm package, so it has nothing to do with changes to the index.php file.

+12
php laravel laravel-elixir laravel-mix
source share
4 answers

There is an undocumented (I believe) method called setPublicPath . Then you can omit the public path from the exit. setPublicPath plays great with underscores.

 mix.setPublicPath('public_html/'); mix.js('resources/assets/js/app.js', 'assets/js') .sass('resources/assets/sass/app.scss', 'assets/css'); 
+19
source share

In Laravel 5.5, I decided like this:

 mix.setPublicPath('public_html/') .js('resources/assets/js/app.js', 'front/js') .js('resources/assets/js/custom.js', 'front/js') .sass('resources/assets/sass/app.scss', 'front/css') .styles('resources/assets/css/custom.css', 'public_html/front/css/custom.css'); 
+2
source share

In Laravel 5.4 you can give us this code:

in AppServiceProvider :

 public function register() { $this->app->bind('path.public', function () { return base_path() . DIRECTORY_SEPARATOR .'public_html'; }); } 
+1
source share

In Laravel 5.8

 mix.config.publicPath='public_html'; mix.js('resources/assets/js/app.js', 'public_html/js') .sass('resources/assets/sass/app.scss', 'public_html'/css'); 
0
source share

All Articles