How to Build SharePoint Framework client side web part – I


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.

Suggested Topics

What is SharePoint Framework (SPFx)

Future prospects of SharePoint Framework (SPFx)

Required tools and libraries for SharePoint Framework (SPFx) development

Setup Microsoft 365 tenant for SharePoint Framework development

Setup SharePoint Framework client side web part development environment

Build SharePoint client side web part using SharePoint Framework (SPFx) – I

Build SharePoint client side web part using SharePoint Framework (SPFx) – II

Build SharePoint client side web part using SharePoint Framework (SPFx) – III

How to Debug SharePoint Framework Solutions in Visual Studio Code

What is the Developers Point of View on SharePoint Framework

What is Required Toolchain for SharePoint Framework

How to Integrate gulp tasks with SharePoint Framework Toolchain

How to Provision SharePoint assets with solution packages

How to Upgrade SharePoint Framework client side solutions in SharePoint Online

Create new web part project

You need to perform following steps:

  1. Create new project directory at your opted location

md helloworld-webpart

  1. Go to project directory

cd helloworld-webpart

  1. Create project using Yeoman SharePoint Generator

yo @microsoft/sharepoint

It will ask for few inputs, provide the inputs as follows:

  1. Solution name? helloworld-webpart
  2. Type of client-side component to create? WebPart
  3. What is the web part name? HelloWorld
  4. What is your web part description? This is my first client side web part using SharePoint Framework
  5. Which framework would you like to use? No JavaScript Framework

At this point, Yeoman will install dependencies and generate files for HelloWorld web part. Once processing is completed, it will show success message.

sharepoint-client-side-web-part-2

 

Using Code Editor

This solution is build using HTML/Typescript. You can use any editor that support client side development.

I am using Visual Studio Code from Microsoft. It is a lightweight but powerful source code editor which runs on desktop of Windows, Mac and Linux. Visual Studio Code supports JavaScript, Typescript and Node.js. It has many extensions for other languages like C++, C#, PHP and Python and runtimes.

 

Preview web part

Run the following command to establish trust

gulp trust-dev-cert

 

sharepoint-client-side-web-part-3

 

You will see a security warning as below, click Yes to install.

 

sharepoint-framework-security-error

 

Now you have installed developer certificate. Run following command to build and preview your web part.

gulp serve

You may be asked for warning. Click Allow access.

sharepoint-client-side-web-part-5

 

SharePoint client side development tool gulp is a task runner which performs build processes tasks such as:

  1. Bundle and Minify JavaScript and CSS
  2. Run tools to call bundling and minifying tasks before each build
  3. Compile CASS to CSS
  4. Compile Typescript to JavaScript

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.

 

sharepoint-client-side-web-part-6

 

You can stop gulp by choosing Ctrl+C in command prompt where gulp is running. Then you will provide answer Y to stop it.

sharepoint-client-side-web-part-7

To Be Continued…


Hope you enjoyed reading it.

Please don't forget to Share, Follow and Like to get updated with latest posts.

It gives me motivation to share more knowledge with you.


About Author

Satyendra Mishra

Project Management Professional (PMP) and Microsoft certified, motivated, energetic and accomplished Project Manager / Architect with 15+ years of work experience in Management, Architecture, Analytics, Development and Maintenance. I have been fortunate to be a part of over 25+ .Net / SharePoint projects delivery with various companies across different industry sectors. This has provided me a valuable insight and experience especially in successful implementation of SharePoint based solutions.

My experience in Web application implementation includes technology strategy and road-map definition, business and technical requirements identification, governance, platform architecture, solution design, configuration, development, quality assurance, training, post-production support, team lead and overall project delivery along with project management.

Satyendra Mishra holds a B.Tech. in Computer Science & Engineering and PG Diploma in Advance Computing from Center for Development and Advance Computing, Pune, India. He is also a certified Project Management Professional (PMP).

I love to share Project Management Tips and Tricks by writing Blogs in the Project Management India Community. I have written around 300+ articles in the Project Management, .Net, SharePoint and related client side technologies.

Related Posts

3 Comments

Leave a Reply

Your email address will not be published.