Hello! I'm working on creating a plugin to add support for Nunjucks. The current documentation suggests the best way to wire up a plugin is to extend your custom Asset class from the exported Asset in parcel-bundler. However, because the end result of my bundling will eventually be html, I feel like what I really want is to extends from HTMLAsset. However, that's not currently possible. (I could reach into node_modules directly to import HTMLAsset, but the split export in index.js makes it difficult.)
You can see this approach being used inside parcel-bundler itself. For example, the CoffeeScriptAsset extends from JSAsset.
All the built in Assets are exposed in the module.
Currently, you can only import Asset.
Expose all the things! I honestly don't know how good/bad that'd be, though.
Wanting to build new plugins, but lean on the good work already available in the main package!
You should be able to do it like this:
const HTMLAsset = require('parcel-bundler/src/assets/HTMLAsset');
class SomeAsset extends HTMLAsset {
   .....
It might still be nice to have this documented or done in a better way.
Thanks! Wouldn't that break down however with the Node 8 split done in index.js?
That suggests that sometimes you'd rather have the lib version, not the src one. I could be entirely off on that! But that was why I didn't go all-in on that method.
Tbh i've not tested node v6 support for this method, would be cool if you could test it and report to this issue if it works or not :)
Hope you don't run into one of the other node 6 issues while testing it though
Relevant to #213.
If every _core_ asset was implemented as a plugin, they could be required independently.
const HTMLAsset = require('parcel-bundler/src/assets/HTMLAsset');
@DeMoorJasper no no no we should not be recommending that people import internal modules, that should not be considered public API and we should prevent people from doing it.
@rdmurphy If you are currently depending on the HTMLAsset that way I recommend you find something else to do or open a PR adding what you need. Do not dive into src
@thejameskyle It is currently the only way, i don't like it either but the API doesn't expose any of the internal assets and in almost any case the assets have to be extended from base assets
I think @brandon93s鈥檚 point makes a lot of sense. Eventually this problem will resolve itself once we figure out #213.
Just a little comment: both base asset types (like JSAsset) and base packagers (like JSPackager) should be exposed - thanks!
Closing this. The pipeline introduced a while ago allows composing multiple asset types together, and it will be further improved in Parcel 2.
Most helpful comment
You should be able to do it like this:
It might still be nice to have this documented or done in a better way.