Documentation
Feedback
Guides
Storefront Development

Storefront Development
Store Framework
Using components
Using the Assets Builder

The VTEX Assets Builder is responsible for handling assets within Store Theme blocks and CSS classes by getting all asset paths used and uploading them in the File Manager service.

As its name implies, the File Manager manages all of your store files and their respective URLs. It is able to translate the asset paths and then export the asset immutable URLs so that all block assets can be properly rendered.

The Assets Builder has two main advantages:

  • You won't need to declare URLs for assets in each blocks, making your code lighter;
  • You can use it whenever you want, having no prerequisites.

Check out the instructions to use it below:

Instructions

  1. Add the assets-builder to your theme's builder list in the manifest.json file. For example:

_10
"builders": {
_10
"assets": "0.x"
_10
},

  1. In the store root directory of your app, create an assets folder to manage your store's assets, such as images.
  2. Then, add the desired asset files in the assets folder. Notice that you can create subfolders within the assets folder to better organize the assets used by the theme blocks, as shown below:

{"base64":"  ","img":{"width":351,"height":361,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":16859,"url":"https://cdn.jsdelivr.net/gh/vtexdocs/dev-portal-content@main/images/vtex-io-documentation-using-the-assets-builder-0.png"}}

If you created subfolders inside the Assets folder, remember to include the folder hierarchy in the asset path, such as: assets/events/vtex-day.jpg.

  1. Use the asset path (assets/{imageFileName}.{jpg/png/gif}) as the value of a given block's prop, such as src, or CSS class for media rendering:

_10
"image": {
_10
"props": {
_10
"src": "assets/myimage.png"
_10
}
_10
}

Once the asset path was added and you save the changes performed, Assets Builder will automatically work to save it in the VTEX IO File Manager and then generate a URL for it, which will be considered by the platform during the theme rendering.

A few things to consider:

  • The Assets Builder is not responsible for URL caching, File Manager is;
  • It is not possible to reference assets through React or other apps;
  • Avoid long file names or unnecessarily heavy assets. This will negatively affect the request payload size and Builder optimization;
  • Any image extension is allowed, such as JPEG, PNG and GIF. Videos are not allowed yet.
Contributors
1
Photo of the contributor
+ 1 contributors
Was this helpful?
Yes
No
Suggest edits (Github)
Contributors
1
Photo of the contributor
+ 1 contributors
On this page