willyelm / pug-html-loader

Pug HTML loader for webpack

Home Page:https://github.com/willyelm/pug-html-loader

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using src=require() doesnt work

matthewjumpsoffbuildings opened this issue · comments

Just creating a new issue since this problem still exists but issue #6 is closed for some reason, and marked as duplicate though I cant see any other issues that it would be a duplicate of.

You should be able to do img(src=require('./path/to/file')) in your pug templates and have the require()d asset be run through webpacks loaders as expected

come here from #6 . You can omit the 'require' part. I'm using img(src="~images/abc") and webpack will try to resolve from root, if you config webpack resolve like this.

{
  resolve: {
    modules: [
      'node_modules',
      'src', // <-- your images folder contained here
    ]
  }
}

Goodluck

Hello! I'm awfully sorry to be reopening something so old, but I was just wondering:

I've gotten the img(src="~images/blah.jpg") method working, but my particular use case actually needs to trigger file-loader on a background image referenced inside of inline css, like this:

.banner-slide(style='background-image: url("~images/heroes/boots.webp");')

Is something like that possible/configurable? (At the moment it looks like it's not.) Thank you!!