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:
If you're using Code Splitting or Module Federation, assets will be inlined into the chunks or containers importing them and should be properly rendered by the host application.
Generally speaking, to inline assets you have to pass inline: true
option to the Assets loader:
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.
Assets loader supports inlining assets with multiple scales.
Keep in mind, 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 Asset loader).
Use combination include
, exclude
and test
(for extensions matching) to configure each rule.
You can read more about Webpack's loader rules here: https://webpack.js.org/configuration/module/#rule-conditions:
test: string | RegExp | Array<string | RegExp>
must match if specifiedinclude: string | RegExp | Array<string | RegExp>
must match if specifiedexclude: string | RegExp | Array<string | RegExp>
must not match if specifiedYou can even use Webpack's Assets Modules if you prefer (with some differences however).