This article describes how we can create a new SharePoint Framework client side web part. We’ll also use various tools to build the web part. Let’s begin with creating a new web part project.
Create new web part project
You need to perform following steps:
- Create new project directory at your opted location
- Go to project directory
- Create project using Yeoman SharePoint Generator
It will ask for few inputs, provide the inputs as follows:
- Solution name? helloworld-webpart
- Type of client-side component to create? WebPart
- What is the web part name? HelloWorld
- What is your web part description? This is my first client side web part using SharePoint Framework
At this point, Yeoman will install dependencies and generate files for HelloWorld web part. Once processing is completed, it will show success message.
Using Code Editor
This solution is build using HTML/Typescript. You can use any editor that support client side development.
Preview web part
Run the following command to establish trust
You will see a security warning as below, click Yes to install.
Now you have installed developer certificate. Run following command to build and preview your web part.
You may be asked for warning. Click Allow access.
SharePoint client side development tool gulp is a task runner which performs build processes tasks such as:
- Run tools to call bundling and minifying tasks before each build
- Compile CASS to CSS
Visual Studio Code provides built-in support for gulp and other task runners. Choose Ctrl+Shift+B on Windows or Ctrl+Shift+B on Mac to debug and preview your web part.
Now, It will launch SharePoint Workbench where you can add your client side web part on the page. This is helpful while development as you don’t need to deploy your client side web part every time while it is under development.
You can stop gulp by choosing Ctrl+C in command prompt where gulp is running. Then you will provide answer Y to stop it.
To Be Continued…