Implement pipelines to compose multiple asset types together #1065
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rather than asset type classes extending one another, Parcel now takes care of composing asset types together. The output returned by an asset type's
generate
method is now recursively processed. This means, for example, that theTypeScriptAsset
just returns JavaScript from its generate method and Parcel will automatically pass this to theJSAsset
for further processing.The API for
generate
changed slightly, but remains backward compatible. Now, instead of using object keys to return multiple renditions from an asset, an array is returned. This allows more options to be specified along with the actual value.There are a couple options that allow some control over how the composition works:
final
option can be specified, which means the code is final and should not be processed by other asset types.hasDependencies
option can be set tofalse
, which means the code is guaranteed not to have any further dependencies in it. This is useful as an optimization. For example, the SASS asset type uses the SASS AST to collect dependencies, so the CSS asset type doesn't need to do it.More options could be added in the future.
This change should be fully backward compatible. If the old API is used, composition doesn't happen at all so it should work exactly the same way as it does today.
This pipeline approach should be much more extendible, especially for plugins which no longer need to rely on the internal asset types in order to extend them. It will also allow us to do things like Vue support much more easily.