Lab - Widget Builder Setup
Summary
In the previous lab, you created a widget template by sending a request to the Widgets API with a REST client. From here on, youโll build widget templates with Widget Builder, a command-line tool that lets you build, edit, and preview widget templates locally, outside the context of your BigCommerce store. In this lab, you will install and configure Widget Builder and create the blank template files for the next lab. You only need to install and configure it once; later labs in this course reuse the same setup.
In this lab you will
- Install Widget Builder
- Configure Widget Builder with your storeโs API credentials
- Create a blank widget template
Prerequisites
- BigCommerce store
- BigCommerce API credentials (Content: Modify)
- Git, Node.js 18+, and npm 9.5.1+ installed locally
Install Widget Builder
- Clone the Widget Builder repository:
- Navigate into the cloned directory and install Widget Builder globally:
- Confirm the install by viewing the available commands:
You should see the usage information for Widget Builder, including commands such as init, start, create, and publish.
Configure Widget Builder
Widget Builder needs your storeโs Client ID, Access Token, and API Path to preview and publish widget templates.
- Create a local directory to hold your widget templates for this course, outside of the
widget-builderrepo you just cloned:
- Run the
initcommand to save your storeโs API credentials:
- Enter the Client ID, Access Token, and API Path for the API account you created in Module 1: Lab - Getting Started, when prompted. This saves an
.envfile in the current directory.
An example session looks like this:
If you need to use different credentials later, run widget-builder init again from the same directory to overwrite them.
The .env file contains your API access token. Keep it out of version control and donโt share it.
Create a Blank Widget Template
Widget Builder can generate a blank widget template to start from.
- From your
~/widget-templatesdirectory, run the following command to scaffold a new widget template:
This creates a ./product-grid directory containing three files:
schema.jsonholds the widget templateโs schemaconfig.jsonholds sample configuration values used by the local previewwidget.htmlholds the widget templateโs markup
Widget Builder also opens a live preview of the starter template in your browser at http://localhost:8080. Leave this running โ the preview refreshes automatically each time you save a file.
In the next lab, you will edit these files to build a widget template.
To see what a finished template looks like in Widget Builderโs format, browse the static content widget from the earlier lab in the static-image-content directory of the lab repository: