-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Encoded inline bundles #3726
Encoded inline bundles #3726
Conversation
Re: detecting binary files, https://www.npmjs.com/package/isbinaryfile has an extra step that counts characters it considers "weird". We could use that module here instead. |
Benchmark Resultspackages/benchmarks/kitchen-sink 🚨
Timings
Cold BundlesNo bundles found, this is probably a failed build... Cached BundlesNo bundles found, this is probably a failed build... packages/benchmarks/react-hn ✅
Timings
Cold Bundles
Cached BundlesNo bundle changes detected. packages/benchmarks/ak-editor ✅
Timings
Cold Bundles
Cached Bundles
|
2a8a310
to
4e7fa48
Compare
2f146d0
to
456afb9
Compare
if (dependency.moduleSpecifier.includes(':')) { | ||
[pipeline, filePath] = dependency.moduleSpecifier.split(':'); | ||
let transformsWithPipelines = {}; | ||
for (let key of Object.keys(this.config.transforms)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also include optimizers here? What if you had a named pipeline that only existed in the optimizer config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Think we should be using the config matching method or just extract the pipelines ourselves here and match against them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we could extract the named pipelines once and cache them? Maybe in the ParcelConfig class?
packages/core/utils/src/string.js
Outdated
@@ -0,0 +1,9 @@ | |||
// @flow strict-local | |||
|
|||
export function escapeJSStringLiteral(str: string): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just use JSON.stringify
?
: packagedBundle.contents | ||
).toString(); | ||
|
||
let inlineType = nullthrows(entryBundle.getMainEntry()).meta.inlineType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do we define what inlineType
values are allowed? I'm not sure it should be enforced in this util in case new ones need to be defined by plugins.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really enforced. inlineType
isn't a formal concept in core and is just something that transformers and packagers agree on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's enforced by the line below asserting the values...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function isn't run in core though, it's run in packagers. Perhaps this util shouldn't live in core/utils
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah true, but the util is still kinda “shared” code that shouldn’t make assumptions if it’s meant to be informal.
456afb9
to
e1f2a1a
Compare
e1f2a1a
to
b189929
Compare
c3ee1c0
to
449490b
Compare
Resolves #3718.
This implements the ability to inline the content of one bundle into another by using protocol-style imports in the form of
data-url:./img.png
to receive a data url orbundle-text:./worker.js
to receive the literal text of the compiled bundle content.This is accomplished by adding
transformer-inline
, which setsisInline
to true on assets, attaching the requested pipeline name to assets and bundles, and adding an optimizer to transform bundle contents into data urls. References to the inline bundle are left behind in the form of bundle ids (this may change with css), and the packaged inline bundles are then replaced during packaging by invoking the inline packaging api.For data urls, the mimetype is automatically determined based on the bundle filepath, and the content is encoded either as text for non-binary content, or as base64 for binary content (content with a 0x00 byte present).
Question: Is there a more robust heuristic for determining binary content than checking for the presence of a 0x00 byte?
Remaining tasks:
Test Plan: Added integration tests.