Images have absolute path - How to use a subdirectory URL in LaravelMix

久未见 提交于 2019-12-05 13:26:38

Answering my own question after a couple of hours of search and trial.

Now my webpack.mix.js looks like this:

const { mix } = require('laravel-mix');
mix
  .setResourceRoot("")
  .js('resources/assets/js/app.js', 'public/js')
  .sass('resources/assets/sass/app.scss', 'public/css');

This will lead to beautifull relative URLs:

<img id="logo" src="images/pat_logo.png">

More Examples

Use mix.setResourceRoot("/") to get an absolute path to the root (should be default):

<img id="logo" src="/images/pat_logo.png">

Or use anything else like mix.setResourceRoot("anything/there/"):

<img id="logo" src="anything/there/images/pat_logo.png">

Cheers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!