Laravel-mix: Image references within Blade templates are not being recognized during build

Created on 19 Jul 2017  路  4Comments  路  Source: JeffreyWay/laravel-mix

  • Laravel Mix Version: 1.2.3
  • Node Version (node -v): 8.1.4
  • NPM Version (npm -v): 5.0.3
  • OS: OSX El Capitan

Description:

I have a fresh install of Laravel and within my blade templates I have references to an image like so:

<a class="navbar-brand" href="#"><img alt="Logo" src="{{ URL::asset('images/logo.png') }}"></a>

I have the image in:

    - assets
        - images > logo.png

But when I run npm run watch Or npm run dev all other image references that I have within CSS and or in a .vue file get optimized and moved into

    - images

except for the image I am pointing to within my blade template. Is there a way to get webpack to parse blade templates for any image references? Or is there a loader that is blade specific.

Or does this need to be a manual process of adding the image to the public directory myself? or to use mix.copy() to copy that directory when the build is run.

Thank you

Most helpful comment

Right... I figured that much but was wondering if there was any plan on creating a blade-loader to check for file formats with .blade? Thanks guys!

All 4 comments

That asset helper is referencing public/images/logo.png, a non-existent image. If I'm not mistaken, in order for an image to be handled by mix and referenced correctly, it must be used in a file managed by webpack / mix. If you have images that aren't referenced in css, scss, less, js, etc., that you also want moved, you need to use mix.copy.

Right... I figured that much but was wondering if there was any plan on creating a blade-loader to check for file formats with .blade? Thanks guys!

I think @andrade1379 has a valid point. I am wondering the same thing.
Clearly there will be many cases when a .css file will only be required in a particular .blade file. Right now, it doesn't get processed by mix. Any plan of a 'blade-loader' to include scss and image files used in .blade templates?

+1 - also required for srcset/sizes-using img elements.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Cheddam picture Cheddam  路  3Comments

pixieaka picture pixieaka  路  3Comments

stefensuhat picture stefensuhat  路  3Comments

terion-name picture terion-name  路  3Comments

amin101 picture amin101  路  3Comments