Recently I was asked to develop a webpart for a modern SharePoint site. My first thoughts were; where do I start, I haven’t done any webpart development for years? I would like to share my journey with you over the next few posts and hope my experience will help new and returning developers along the way.
Development Environment & Tools
Code Editor or Integrated Development Environment (IDE).
If you have not done so already, install your preferred Integrated development environment (IDE). My choice is Visual Studio Code, however there are three supported code editors:
Tip: Hold [Ctrl]+[`] will open the Terminal window in VS Code.
Set up your SharePoint Framework development environment
In my opinion Microsoft has done a good job in publishing a collection of articles describing how to build and deploy your first webpart. I would recommend starting by reading the “Set up your SharePoint Framework development environment” articles to get yourself up and running
- At the time of writing this article, the SPFx Framework does not support the latest TLS (long term support) version of Node.js. Installing the wrong version will cause you headaches, so read “Important” notes under the Install Node.js section before you install Node.js
- Click here to navigate the Node.js v10.x, use the Node.js > Downloads > Previous Releases page.
Already have Node.js installed?
As a Windows 10 user, I opened “Add or remove programs” and entered Node into “Search this list” and checked the version before running executing the node-v10.22.0-x64.msi file.
The following command can be used to check the version installed:
Trusting the self-signed developer certificate
Don’t forget to configure a self-signed SSL certificate which can be done by running the following command.
You will use this when testing your custom solutions from your development environment which uses HTTPS by default.
Tip: I use Google Chrome’s persons (profiles) to switch between Tenants and Accounts. I understand that other browsers now include similar functionality.
I like this code editor for its simplicity and Plugins, such as: JSON Viewer and XML Tools.
Captures all HTTP(S) traffic between your computer and the Internet with Fiddler HTTP(S) proxy. Inspect traffic, set breakpoints, and fiddle with requests & responses.
Helps you build, connect and test APIs. An example is testing the Microsoft Graph API.
VS Code Extensions
Focused on SPFx development:
- Debugger for Chrome
- Debugger for FireFox
- Debugger for Microsoft Edge
- React Native Tools
For Source control:
- Git Merger
- Azure Account
- Azure Functions
- Azure Repos
- Code Spell Checker
- Edit CSV
- Paste JSON as Code
- Rainbow CSV
Frameworks & Fashion
When the SPFx framework came on the scene the “AngularJS verses React (ReactJS)” conversation was fresh. While I built a handful of SPFx Webparts and Extensions I have to acknowledge things have moved on since then…
Back to School
Even though I had done these tutorials a few years ago, I found it invaluable to do them again:
Another great place to start with is the SharePoint Framework Client-Side Web Part Samples website and check out the Getting Started page. You can either clone the GitHub repository or just explore the code online.
If you are anything like me, I would recommend avoiding the following pitfalls:
- Using someone else’s code may seem like a great idea, however unless it does 90% or more of what you require you may find yourself spending more time trying to understand the code rather than writing new functionality.
- Getting bogged down in detail; this can easily happen if like me you enjoy detail. My strategy to avoid this is to draw wire-frames and carry out research (e.g. frameworks etc) before the build officially begins.
- Avoid the muddying of data and presentation code/layers; this is an area I can get bogged down in, however on a positive side the cleaner the separation the easier the code is to support and maintain.
- Unable to upgrade frameworks. It’s not always obvious what is going on, however if you find your projects are being scaffolded with old version npm packages then try retracing your steps and uninstalling everything including Node, before reinstalling again.
For my next post I will focus on design and frameworks.