Parcel Externals

Parcel is an awesome bundler, however, some (more exotic) things are missing. Let's make it one less.

In Piral we required a way to strip to some dependencies; by just referring to an already available dependency. A dependency that is omitted from the bundle is usually called an external. Webpack brings this functionality out of the box, but the more complete solution (Parcel) does not.

Support for a "static" version of this feature is simple. We just need to override Parcel's asset resolution algorithm to use a new custom module when a module from an external has been resolved. However, the tricky part lies in providing a "dynamic" version of this feature.

The difference between the static and dynamic one can be found in the options. While a static version will always come up with a module that essentially just uses require at runtime, a dynamic version can come up with whatever module. One example is the resolution from the global context, or considering submodule support.

Since we already implemented the support for externals in Piral it was quite straight forward to just extract this functionality in a plugin, that can be used in any project that uses Parcel. As a side-effect we also get feedback (issues / enhancements / ...) regarding this feature from non-Piral users, which gives us significant benefits.

Parcel is an awesome piece of technology. We do not regret choosing Parcel as the core technology in the Piral CLI and we will happily migrate to Parcel v2 when the time is right. Having externals support in Parcel should actually boost adoption, too.

Created .

References

Sharing is caring!