Introduction

SharePoint Framework in the recent release provides us with the capability of provisioning SharePoint assets, using configuration files of SharePoint Framework code.

To create SharePoint list, there is a way to add by using list definition files in Visual studio SharePoint project. Likewise, we can add the list definition XML in the elements file and provision the lists, using SharePoint framework project.

In this sample, let us try to create a simple SharePoint list, using SPFx project.

Prerequisite

To setup the development environment, please follow the steps provided by the Microsoft team.
In my previous articles, you have seen about SPFx introduction, prerequisites, steps for setting up the environment and developing and testing the Web parts, using the local environments.
Steps involved

Create a SharePoint Framework project by running the command yo @microsoft/sharepoint.

The list will be created, using definition file (elements.xml). Now, to add the elements.xml file to the project, create Sharepoint/assets folders to the root project folder and add the element.xml file. The snapshot given below shows the folder and the created files.

Add the list instance definition in the elements.xml file. XML given below shows the definition to create a custom list called TestSPFxList. The feature ID for custom list template is 00bfea71-de22-43b2-a848-c05709900100. Likewise, to get the feature Id of the other templates, please refer the technet blog here.

Copy the piece of XML content given below and paste it in definition file (elements.xml).

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  3. <ListInstance
  4. FeatureId="00bfea71-de22-43b2-a848-c05709900100"
  5. Title="TestSPFxList"
  6. Description="New SP List"
  7. TemplateType="100"
  8. Url="Lists/TestSPFxList">
  9. </ListInstance>
  10. </Elements>

To make the list to be available under the feature, the elements file should be mapped to the features, using the package-solution.json file.

The snippet given below shows the solution JSON along with the feature details and package path.

  1. {
  2. "solution": {
  3. "name": "spassetsprovisioing-client-side-solution",
  4. "id": "727f23bb-9532-45ee-bb1d-2e48d8757509",
  5. "version": "1.0.0.1",
  6. "features": [{
  7. "title": "assetsprovisioning-solution",
  8. "description": "assetsprovisioning-solution",
  9. "id": "479e94c9-c6f2-4393-bdf1-54545d8b8a2d",
  10. "version": "1.0.0.1",
  11. "assets": {
  12. "elementManifests": [
  13. "elements.xml"
  14. ]
  15. }
  16. }]
  17. },
  18. "paths": {
  19. "zippedPackage": "solution/spassetsprovisioing.sppkg"
  20. }
  21. }

Deploy/ Run

The package should be deployed to SharePoint site (Office 365 site). Bundle and package the solution before uploading it to the site.

The article givenn below shows the detailed steps for bundling, packaging and deploying.

The snapshot given below shows the app added and the list provisionined on the site.
Summary

Thus, you have learned adding/provisioning SharePoint list, using SharePoint Framework Web part solution.

What Next
In my next articles, you will see how to add other SharePoint assets to the site, using SPFx solution.