Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parcel 2: Runtime plugins and bundle loader support #2534

Merged
merged 19 commits into from
Jan 22, 2019
Merged

Conversation

devongovett
Copy link
Member

This implements support for runtime plugins in core, and the default runtime plugin for browser/node environments as discussed in #2507. It gets a bunch of the async import integration tests passing.

Runtime plugins are passed a Bundle, and can modify it in some way to add assets as needed. For example, the default runtime for JS adds loader runtimes to load bundles on demand for async imports. It will also inject the HMR runtime in the future. Runtime plugins are called in the BundlerRunner just after bundles are created and named, and before packaging.

This deviates from the Parcel 2 RFC in that Loader plugins are replaced by Runtime plugins, which are a bit more flexible and easier to implement in a generic way.

Note that the interface exposed to runtime plugins to add assets is a hack at the moment and we need to decide where it will go. I will be opening up a separate issue to discuss this and the rest of the AssetGraph/BundleGraph interface that we want to expose to plugins.

Summary of changes

  • Separates asset graph building from Parcel into its own AssetGraphBuilder class, which can be called to generate an asset graph from anywhere without running the rest of parcel. When watching is enabled, AssetGraphBuilder emits an event to let Parcel know that something was invalidated, and Parcel rebuilds.
  • Support creating an asset graph from code rather than from a file. This allows runtime plugins to generate code at build time that isn't stored in a file, and have it go through the same pipeline as the rest of the code. It works by adding an optional code property to a TransformerRequest so that TransformerRunner uses that code rather than reading from a file.
  • Fixes node global insertion (e.g. Buffer, process, etc.) so that it will not occur if a local variable of the same name is defined. This was happening with importing lodash for example. Probably should also apply this fix to Parcel 1.
  • Fixes an issue where one of two separate bundles which point to the same third bundle did not get a reference in the BundleGraph properly since nodes are not revisited during traversal. Fix is to ensure that all dependencies which have an associated bundle_group are replaced in every bundle.

@padmaia
Copy link
Contributor

padmaia commented Jan 22, 2019

Found some things unrelated to the runtime plugins, but we've discussed those. Otherwise LGTM.

@devongovett devongovett merged commit a98f27d into v2-work-so-far Jan 22, 2019
@devongovett devongovett deleted the loaders branch January 22, 2019 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants