Is it possible to support pug assets root path
Opened this issue · 2 comments
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
- server/index.js with koa/koa-static always return html page rendered by pug engine
- public will have a dist to serve in production
- bin/build run the parcel build task to compile assets/*.pug which only have css/js
In development:
- visit http://localhost:3000, should get index.pug with public/js/index.js
- visit http://localhost:3000/detail/1, should get detail.pug with public/js/detail.js
In production:
- visit http://localhost:3000, should get index.pug with public/dist/{md5-index}.js
- visit http://localhost:3000/detail/1, should get detail.pug with public/dist/{md5-detail}.js
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
@huanglong I'll check it a little bit later, thanks for issue!
@Ty3uK 👌 ,Looking forward to this enhancement.