Ty3uK / parcel-plugin-pug

Pug template support for Parcel bundler
MIT License
46 stars 6 forks source link

Is it possible to support pug assets root path #4

Open huanglong-zz opened 6 years ago

huanglong-zz commented 6 years ago

Parcel-plugin-pug is really handy to use. However, when it comes to production, something inconvenient come out.

Here is the pug project:

. project
├── bin
│   └── build
├── package-lock.json
├── package.json
├── public
│   └── js
│       ├── detail.js
│       └── index.js
└── server
    ├── index.js
    └── views
        ├── assets
        │   ├── script.pug
        │   └── script2.pug
        ├── detail.pug
        └── index.pug

In development:

In production:

But parcel always compile files recording to the relative path which is defined in server/views/assets, that means it has to be ../../../public/js/index.js.

So the only way I found is always using /js/index.js /js/detail.js instead.

Then I think maybe parcel-plugin-pug could nest this config for this compiling case. It will treat anything normal just like before, but when it meets some assets where the path start with /, it will know all the relative files is relative to public/.

Here is the repo: https://github.com/huanglong/parcer-bundle-test

npm run start for development
npm run build for build
npm run production for both build and production
Ty3uK commented 6 years ago

@huanglong I'll check it a little bit later, thanks for issue!

huanglong-zz commented 6 years ago

@Ty3uK 👌 ,Looking forward to this enhancement.