A
A
Anton Shilov2019-08-29 14:55:04
Pug
Anton Shilov, 2019-08-29 14:55:04

How to get rid of long relative paths in require src in pug templates with webpack setting?

How to avoid view paths in pug/jade template files:

img.css_class(src=require("../../../img/spinner.png"))

And it's easy to write:
img.css_class(src=require("./spinner.png"))
Part of the webpack config
module: {
    rules: [
      {
        test: /\.(jade|pug)$/,
        use: [
          {
            loader: 'pug-loader',
            options: {
              self: true,
              globals: true,
              pretty: true,
              compileDebug: true
            }
          }
        ]
      },
      {
        test: /\.(jpe?g|png|gif|svg|ico)$/i,
        use: [
          {
            loader: 'file-loader',
            options: {
              name: '[name]-[hash].[ext]',
              outputPath: 'src/img/',
              publicPath: 'src/img/'
            }
          },
          {
            loader: 'image-webpack-loader',
            options: {
              mozjpeg: {
                progressive: true,
                quality: 65
              }
            }
          }
        ]
      }
    ]
}

What else needs to be written in the webpack config? Tell me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Suha, 2019-08-29
@Siggard

it ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question