parcel-plugin-pug icon indicating copy to clipboard operation
parcel-plugin-pug copied to clipboard

Is it possible to support pug assets root path

Open huanglong-zz opened this issue 7 years ago • 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-zz avatar Jan 17 '18 11:01 huanglong-zz

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

Ty3uK avatar Jan 17 '18 11:01 Ty3uK

@Ty3uK 👌 ,Looking forward to this enhancement.

huanglong-zz avatar Jan 18 '18 02:01 huanglong-zz