webdiscus / pug-plugin

Renders Pug template to HTML or template function. Resolves source files of scripts, styles, images in Pug . Uses Pug template as entry point.
https://webdiscus.github.io/pug-plugin/hello-world
ISC License
73 stars 8 forks source link

Only use PugPlugin.loader but can't compile images #47

Closed oodzchen closed 2 years ago

oodzchen commented 2 years ago

I've use PugPlugin.loader to preprocess the pug templates in my project, only use the loader without initial the plugin. It work fine when at development mode, but when build it in production mode, all images referenced in the pug files can't compile to the output directory.

Here is the code in base webpack config

...

  {
    test: /\.pug$/,
    use: {
      loader: PugPlugin.loader,
      options: {},
    },
  },

...

  new HtmlWebPackPlugin({
    filename: `${page}.html`,

    // template for individual pages index, about and contact
    template: `./src/templates/${page}.pug`,
    chunks: [share, page],
    chunksSortMode: 'manual',
  })

How can I make it work with minimal changes, I'd like to use only the loader instead of replace all other things with PugPlugin.

webdiscus commented 2 years ago

Hi @oodzchen,

can you please create a small repo with reproducible issue?

P.S. Using pug loader with HtmlWebPackPlugin is deprecated, because this way is inefficiently and very terrible. The correct and very easy way to render Pug templates is to use Pug plugin.

webdiscus commented 2 years ago

@oodzchen

I need see your Pug template and full Webpack config. Please, complete the issue with a small repo and then reopen this issue.

oodzchen commented 2 years ago

@webdiscus Looks like it's because I didn't use require on image files, I've fixed already.