15

I have a project with this structure:

src
 |- index.pug
 | - layout
 |     |- index.less
 | - scripts
 |     |- index.js

For now, when I run parcel build src/index.pug, all the files are bundled and I've got this on the distribution folder:

dist
  |- index.html
  |- index.12345.css
  |- index.12345.js

When I was spected something like:

dist
  |- index.html
  |- layout
  |    |- index.12345.css
  |- scripts
  |    |- index.12345.js

So, my question is: Can I specify the output path for my css, js and images using ParcelJS?

Renan Gomes
  • 771
  • 1
  • 15
  • 34
  • Don't think you can, non entry point assets are hashed and moved to root (folder structure is flattened): https://github.com/parcel-bundler/parcel/issues/872 – nathan Aug 12 '18 at 16:50
  • You might find a solution among the Namer plugins: https://parceljs.org/plugin-browser/?type=%22namer%22&page=0&filter=%22%22&includeOfficial=false – fregante May 01 '23 at 15:22

2 Answers2

7

Parcel doesn't support this feature out of the box, but I've developed a plugin for it. Check it out https://www.npmjs.com/package/parcel-plugin-custom-dist-structure

It is suitable for all types of web/node development projects, it will generate the dist structure you specify while also handle your imports.

Let me know what you think!

  • Had some issues when changing files that referenced images, but once I restarted `npx parcel serve index.html`, it worked fine. If it becomes more of a problem, I'll see if I can reproduce it consistently and submit an issue. – Chinoto Vokro May 18 '20 at 01:16
  • A very good plugin, but unfortunately it somehow does not change the reference to css in html (works for scripts though): https://github.com/VladimirMikulic/parcel-plugin-custom-dist-structure/issues/36 – Eric Xin Zhang Dec 03 '20 at 11:26
  • It's a cool plugin but parcel 1 is deprecated and this plugin doesn't currently support parcel 2, sadly. – Roman Starkov Apr 18 '21 at 12:42
  • 1
    @EricXinZhang your issue has been fixed :) – Vladimir Mikulic Apr 19 '21 at 13:06
  • @RomanStarkov thanks for your intereset. A few days ago I migrated two of my Parcel plugins to version 2 and I will hopefully soon migrate parcel-plugin-custom-dist-structure too. – Vladimir Mikulic Apr 19 '21 at 13:10
  • @VladimirMikulic That's great news, I hope you do! We use your plugin with parcel 1 and it does a great job. – Roman Starkov Apr 19 '21 at 13:42
5

With version 1 it's not supported. This is supposed to be available in version 2 through user plugins. See https://github.com/parcel-bundler/parcel/issues/233

tcurdt
  • 14,518
  • 10
  • 57
  • 72