webdiscus / pug-loader

Pug loader for Webpack renders pug to HTML or template function
https://webdiscus.github.io/pug-loader/pug-filters
ISC License
72 stars 5 forks source link

Windows only: Invalid path when using alias #3

Closed alterastro closed 2 years ago

alterastro commented 2 years ago

File paths are not handled correctly when using the alias in include and extends. The path specified in the alias is always glued to the path to the current template file.

In the case of extends, I get D:\\projects\\new-app\\src\\pages\\main\\D:\\projects\\new-app\\src\\layouts\\default\\default.pug And in the case of include - D:\\projects\\new-app\\src\\layouts\\default\\D:\\projects\\UI\\src\\components\\XApp\\XApp.pug

In this case, the correct values for the alias are displayed in the console:

Exo path: D:/projects/UI/src/components
Layouts path: D:\projects\new-app\src\layouts

The following aliases have been added to the webpack config:

alias: {
  UI: 'D:/projects/UI/src/components',
  Layouts: path.resolve('src', 'layouts'),
},

My project uses the following structure:

src/
├── ...
│
├── layouts/
│   ├── default/
│   │   ├── ...
│   │   └── default.pug
│   └── ...
│
├── pages/
│   ├── main/
│   │   ├── ....
│   │   └── main.pug
│   └── ...
│
└── ...

Layout code:

- var head = {}

block variables

include ~UI/XApp/XApp

doctype html
html
  head
    meta(charset="UTF-8")
    meta(name="viewport" content="width=device-width, initial-scale=1.0")
    meta(http-equiv="X-UA-Compatible" content="ie=edge")

    block head
      title.
        #{head.title || 'Default title'} - My Webpage
  body
    +x-app
      block content

Page code:

extends ~Layouts/default/default

block variables
  -
    var head = {
      title: 'Main page'
    }

block content
  h1 Hellow pug!
webdiscus commented 2 years ago

Hello @alterastro,

can you please run the tests from the repo directory:

npm run test

Whether all tests will be passed on your system?

See the test alias in extends. See the test alias in include. See the test alias in require.

All tests are passed on:

alterastro commented 2 years ago

Hello @webdiscus,

Did as in your suggestion, but it didn't help. Unfortunately, this solution does not help either for UI or Layouts. I still get concatenated paths (

webdiscus commented 2 years ago

Hello. @alterastro,

I have fixed the issues on windows (tested on Win 10), ver. 1.5.1. Can you please try test it?

alterastro commented 2 years ago

Hello. @alterastro,

I have fixed the issues on windows (tested on Win 10), ver. 1.5.1. Can you please try test it?

Everything works great now! Thank you so much for your work!

(my system: Windows 10 21H1, 19043.1348)

webdiscus commented 2 years ago

Hello @alterastro,

very nice :-) Then this issue can be closed.