Parcel: What are the options that `addDependency` takes?

Created on 9 Nov 2018  ·  1Comment  ·  Source: parcel-bundler/parcel

❔ Question

What are the options that addDependency takes?

🔦 Context

It isn't really relevant, but I'm trying to write a plugin, and it goes something like this…

  • '.map' files contain links to '.set' files.
  • '.set' files contain links to '.png' files.
  • The '.map' files need to be converted to JS modules.
  • The '.set' files need to be embedded in the transformed '.map' files.
  • The '.png' files need to be copied over to the output, and their URLs need to be inserted appropriately in the '.map' files.
Question

Most helpful comment

I'm a bit in the same situation and my findings are:

addDependency with or without includedInParent option:

  1. addDependency(path)
  2. create an Asset for the target file and add to bundle along with parent,
  3. adds a watcher for changes of the target file,
  4. and rebuild the aformentioned Asset when it changes.

  5. addDependency(path, { includedInParent: true })

  6. do not create an Asset, do not process,
  7. add a watcher for changes of the target file,
  8. and re-build the parent asset when the target file changes.

path rules

  1. path should be a relative path following require rules (e.g. ./foo.ext); it can't be absolute.

  2. path can be a specific file or a "glob" pattern (e.g. **/*.ext), in which case:

    1. if NOT includedInParent, every single file matching the glob will be bundled and watched individually,
    2. if includedInParent, the glob path will be watched BUT it will fail to get the parent rebuilt because of bug #2483

For your project I suppose you should define a MapAsset for .map files extending JSAsset, overload the load method to produce JS including the .set files. Individual .set file should be linked as includedInParent dependencies of the MapAsset, and the generated JS would refer to the images using relative require calls.

>All comments

I'm a bit in the same situation and my findings are:

addDependency with or without includedInParent option:

  1. addDependency(path)
  2. create an Asset for the target file and add to bundle along with parent,
  3. adds a watcher for changes of the target file,
  4. and rebuild the aformentioned Asset when it changes.

  5. addDependency(path, { includedInParent: true })

  6. do not create an Asset, do not process,
  7. add a watcher for changes of the target file,
  8. and re-build the parent asset when the target file changes.

path rules

  1. path should be a relative path following require rules (e.g. ./foo.ext); it can't be absolute.

  2. path can be a specific file or a "glob" pattern (e.g. **/*.ext), in which case:

    1. if NOT includedInParent, every single file matching the glob will be bundled and watched individually,
    2. if includedInParent, the glob path will be watched BUT it will fail to get the parent rebuilt because of bug #2483

For your project I suppose you should define a MapAsset for .map files extending JSAsset, overload the load method to produce JS including the .set files. Individual .set file should be linked as includedInParent dependencies of the MapAsset, and the generated JS would refer to the images using relative require calls.

Was this page helpful?
0 / 5 - 0 ratings