There are some situations when you might want to inline assets into the JavaScript bundle, instead of extracting them into standalone files.
Common examples of such use cases are:
Inlining assets into the bundle makes the bundle size larger and increases the initial startup time of an app. It's most noticable when you inline an asset which has 3 scales (e.g. @1x
, @2x
and @3x
). In that scenario, all of the scales will be inlined into the bundle since it's not possible to determine which scale is needed at runtime.
To inline assets you have to pass inline: true
option to the Assets loader:
You can also use the inline: true
option in the getAssetsTransformRules helper function:
This will cause all assets processed by Assets loader in the rule to be inlined into the JavaScript bundle.
Inlined assets are imported in the same way as extracted assets:
The value of image
in this example would be either an object with uri
, width
, height
and scale
or an array of such objects, in case there are multiple scales.
You can provide multiple rules with Re.Pack's Assets loader - one rule would extract the assets and another would inline them. There's no limit how many of these rules you could have.
Make sure you configure those rules not to overlap, so that any single asset is only processed by one rule (by one Assets loader). Use combination of include
, exclude
and test
(for extensions matching) to configure each rule.
You can read more about loader rules and how to configure them in: