Parcel: Assets output path

Created on 8 May 2019  ·  9Comments  ·  Source: parcel-bundler/parcel

❔ Question

Is there any way to set assets path/folders ?

something like

parcel ./index.html --assets-dir '_'

🔦 Context. After build:

I have:

image

I need:

image

or

image

💻 Code Sample

const Bundler = require('parcel-bundler');

(async () => {
  const entryFiles = ['./src/main/index.html'];

  const bundler = new Bundler(entryFiles, {
    hmr: true,
    cache: true,
    sourceMaps: true,
    autoinstall: false,
    throwErrors: false,
    scopeHoist: false,
    target: 'browser',
  });

  const bundle = await bundler.serve();
})();

🌍 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.12.3
| Node | v10.15.3
| Yarn | 1.15.2
| Operating System | MacOS

Feature static ✨ Parcel 2

Most helpful comment

I like the new plugin structure that Parcel 2 brings to the table. But for the use-case of defining an output folder, creating a bespoke plugin package seems like a relatively high barrier.

Example

I’m trying to integrate Parcel 2 into an old CMS project whose templating system relies on folder structure conventions. I have two entries: one Pug partial to be included before </head> and another to be included before </body>. I need to place those *.html assets in a directory public/templates/includes/ while putting everything else into public/dist/.

Suggestion

Maybe implementing the below option could lessen this barrier? It’d simply map asset types to destination folders.

.parcelrc

{
  "output": {
    "*.html": "./public/templates/includes/",
    "*": "./public/dist/"
  }
}

Or maybe an option like this can be passed to the default namer?

All 9 comments

Currently impossible, will be possible in Parcel 2

cool

@notiv-nt , if you need a temporary solution until Parcel 2 gets delivered, I've written a simple script that moves assets to a separate directory after Parcel build. You can find it here:
https://medium.com/hceverything/parcel-js-moving-static-resources-to-a-separate-folder-aef63a038cbd?postPublishedType=repub

Is this feature available int the current version of parcel 2?
if not, is it included in any of the current alpha milestones?

You can write a custom Namer plugin to support things like this. See how the default namer works for an example: https://github.com/parcel-bundler/parcel/blob/v2/packages/namers/default/src/DefaultNamer.js

looks like the problem(and the solution) is linked to #233
maybe it is better to mention the "custom Namer plugin" solution over there for future reference.
thanks.

I like the new plugin structure that Parcel 2 brings to the table. But for the use-case of defining an output folder, creating a bespoke plugin package seems like a relatively high barrier.

Example

I’m trying to integrate Parcel 2 into an old CMS project whose templating system relies on folder structure conventions. I have two entries: one Pug partial to be included before </head> and another to be included before </body>. I need to place those *.html assets in a directory public/templates/includes/ while putting everything else into public/dist/.

Suggestion

Maybe implementing the below option could lessen this barrier? It’d simply map asset types to destination folders.

.parcelrc

{
  "output": {
    "*.html": "./public/templates/includes/",
    "*": "./public/dist/"
  }
}

Or maybe an option like this can be passed to the default namer?

Hi everyone!
Being stuck with this issue myself, I've created a plugin that allows us to specify a custom dist structure.
https://github.com/VladimirMikulic/parcel-plugin-custom-dist-structure

@bro-strummer @notiv-nt @DeMoorJasper I would appreciate your feedback on this!
Thanks.

Hi,

Just another plugin addressing this kind of issue
https://www.npmjs.com/package/parcel-namer-rewrite

Feel free to leave a feedback on that
Thanks

Was this page helpful?
0 / 5 - 0 ratings