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: Default bundle namer #2424

Merged
merged 7 commits into from
Dec 25, 2018
Merged

Parcel 2: Default bundle namer #2424

merged 7 commits into from
Dec 25, 2018

Conversation

devongovett
Copy link
Member

This implements bundle naming using namer plugins, and provides the default namer plugin for Parcel 2.

Closes #2240. Fixes #2140.

Summary of changes:

  • Implements default namer plugin, which implements the rules set out in Parcel 2: NamerRunner and default namer plugin #2140 including content hashing.
  • Marks bundles as entry bundles in the default bundler. Entry bundles are not content hashed.
  • Propagates targets from the initial dependency created for the original entries to all bundles in the bundle graph.
  • Uses user-defined filenames from targets for original entry bundles. Other bundles that are produced from this entry point are created in the same directory.
  • Adjusts targets to make explicit output filenames optional. If not provided, parcel uses its default file naming scheme.
  • Adds an outputHash property to Asset which is computed at the end of the transformer pipeline. The current hash property is computed after the first transform and is used for caching. The outputHash is used for content hashing.

if (bundle.filePath) {
// TODO: what about multiple assets in the same dep?
// e.g. input is a Vue file, output is JS + CSS
// which is defined as a target in package.json?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any ideas how we could tell which one is the main one? Should we take the specified filename and just replace the extension with the bundle type?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that works.

return bundle.filePath;
}

// TODO: if split bundle, base name on original bundle names?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any ideas on how to get the information on the original bundles that the split bundle originated from here? I'd rather not add a reference to the original bundles to the bundle object but that may be the only way...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only other way I could think of would be to pass in the bundleGraph along with the bundle to be named.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could possibly work. The split bundle will be connected to both original bundle groups, but there is currently no way to know which bundle connected to a bundle group was the original one...

let entryFilePath = entryAsset.filePath;
let name = path.basename(entryFilePath, path.extname(entryFilePath));

// If this is an entry bundle, exclude the hash and use the original relative path.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reasoning for this again?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have index.html as an entry point, you typically want to keep that name rather than adding a content hash. Otherwise the link would change every time you deploy. Same thing for things like service workers, where the URL can never change.

Here is the original RFC: #872

@devongovett devongovett merged commit 7af2661 into v2-work-so-far Dec 25, 2018
@devongovett devongovett deleted the default-namer branch December 25, 2018 05:10
@mischnic mischnic mentioned this pull request Jan 9, 2019
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