Creating Custom Solutions with SharePoint Framework (SPFx) in 2023

AllianceTek Inc.
7 min readOct 17, 2023

The SharePoint landscape has seen a transformative shift, largely due to the introduction of the SharePoint Framework (SPFx). Embraced by organizations globally, SPFx has risen to prominence, establishing itself as the go-to methodology for customizing and enhancing the SharePoint experience. Its flexible, client-side development model champions a modern web development approach, perfectly aligning with the evolving needs of today’s digital enterprises.

For developers well-versed in the intricacies of SharePoint, the advent of SPFx offers an enriched toolkit, unlocking a realm of innovative possibilities. Yet, even for those on the precipice of their SharePoint journey, SPFx serves as a welcoming gateway, ensuring that entering this dynamic world is as intuitive as it is rewarding.

With its unique blend of versatility and efficiency, SPFx is no longer merely an option — it’s imperative for anyone serious about tailoring SharePoint to meet specific organizational needs. Through this guide, readers will embark on a comprehensive exploration of the pivotal concepts intrinsic to SPFx. From foundational principles to nuanced development practices, this resource aims to be your trusted companion as you navigate the multifaceted corridors of SPFx-driven solutions.

Brief History and Evolution

With the shift towards cloud services and the ubiquity of JavaScript in web development, Microsoft recognized a need to modernize its approach to SharePoint customization. Enter SPFx. Launched in 2017, the SharePoint Framework heralded a new era for SharePoint developers. Unlike the preceding SharePoint Add-ins model, which had a mix of client-side and server-side components, SPFx took a bold step towards a fully client-side model.

This shift was significant. It not only aligned SharePoint with contemporary web development practices but also enhanced performance, reliability, and user experience. The framework was tailored for the modern, dynamic web pages users had come to expect, transitioning away from the static pages of the past.

Why Use SPFx

  • Modern Development Practices: SPFx is built upon popular open-source tooling, such as Node.js, React, and TypeScript. This allows developers to harness the power of the broader web development community and its resources.
  • Seamless Integration: SPFx ensures a smooth experience across various platforms. Whether you’re working with SharePoint Online, a hybrid scenario, or even extending capabilities into Microsoft Teams, SPFx is designed for compatibility.
  • Enhanced Performance: By being purely client-side, SPFx web parts and extensions load in the user’s browser without the overhead of server-side rendering. This ensures faster page load times and a more responsive user interface.
  • Secure and Scoped: SPFx operates within the confines of the browser’s security context. It respects SharePoint permissions, ensuring that custom solutions cannot bypass established security protocols.

Components of SPFx

  • Client-Side Web Parts: These are modular, reusable components that can be dragged and dropped onto SharePoint pages. Web parts can display content, integrate with external services, or provide interactive features, all running in the user’s browser.
  • Extensions: These provide ways to customize the SharePoint user experience beyond just web parts. Examples include modifying the SharePoint header and footer, custom actions in lists, or even field customizations in list views.
  • Libraries: Libraries in SPFx are reusable pieces of code that can be shared across multiple web parts or extensions. Instead of duplicating functionality, developers can maintain a set of common functions in a library, promoting better code organization and efficiency.

Setting up the Development Environment for SharePoint Framework (SPFx) Development

Creating custom solutions in SPFx requires a unique development environment setup. This environment, tailored to SharePoint’s requirements, allows developers to effectively build, test, and deploy their solutions. Let’s dive deeper into how you can set up this development environment:

Prerequisites

  1. Node.js

“Node.js is an open-source JavaScript platform. It’s essential for SPFx development, enabling tasks like setting up projects, building, and testing locally.

Visit the official Node.js website. For SPFx, ensure you’re installing a version that’s recommended by the SharePoint Framework documentation. Often, this may be a Long-Term Support (LTS) version.

2. Yeoman & Gulp:

Yeoman is a scaffolding tool for modern web applications. It uses generators, like the SharePoint Yeoman generator, to set up projects quickly, ensuring they have the right file structure and dependencies.

Gulp is a task runner that automates processes in your development workflow, such as compiling TypeScript files, bundling and minifying scripts and styles, and much more.

Configuring a Development Workspace

Your development workspace is essentially a dedicated directory (or set of directories) on your computer where you’ll house your SPFx projects. Keeping a dedicated workspace is essential for organizational purposes and ensures smooth operations, especially when working on multiple projects.

Steps:

  • Choose a suitable location on your computer. This could be a folder in your documents, a separate partition, or even a directory in a cloud-synced folder.
  • Create a new folder named “SPFx Workspace” or something similar.
  • Whenever you’re about to create a new SPFx project using Yeoman, navigate to this workspace directory first. This ensures all your SPFx projects are organized in one place.

Creating Your First SPFx Web Part

The SharePoint Framework (SPFx) offers developers a client-side method to enhance and extend SharePoint’s capabilities. Crafting your initial SPFx web part is an exciting initiation into the world of modern SharePoint development. Here’s a step-by-step breakdown:

  1. Using Yeoman to Scaffold a New SPFx Project

Yeoman, widely regarded as the “scaffolding tool for modern web apps,” provides a seamless experience to initiate SPFx projects.

Begin by moving to your desired workspace directory using your terminal or command prompt.

Once in the directory, you’ll need to initiate the Yeoman SharePoint generator. This step will commence the creation of your SPFx project’s foundational structure.

Yeoman isn’t just a silent worker; it interacts with you. Upon activation, it will present a series of prompts on-screen. These questions aim to determine your project’s parameters, such as the name of the solution, whether you’re targeting SharePoint Online or an On-Premise version, and if you wish to include a default web part. Make your selections based on your project’s needs.

2. Understanding the Generated Project Structure

After Yeoman has completed its setup, you’ll be provided with a specific SPFx project structure. Familiarizing yourself with this layout is crucial:

  • src: This is where the meat of your project lies. It’s the repository for the source code of all your web parts, extensions, and other custom functionalities.
  • config: This directory, as its name suggests, is all about configurations. It determines how your project is bundled and the specifics of how it’s packaged.
  • node_modules: It’s the storage hub for all the NPM packages and dependencies your project requires.

3. Developing and Testing in the Local Workbench

One of the standout features of SPFx development is the local workbench. This tool simulates a SharePoint environment, allowing you to observe and test your web parts without deploying them onto a live SharePoint site.

The local workbench can be initiated with a specific command. Once activated, your default browser springs to life, showcasing a SharePoint-themed page.

Here, in this simulated environment, you can add your web parts, tweak their settings, and test their functionalities in a controlled setting.

However, do remember that this environment is a simulation. It won’t connect to live SharePoint data. Hence, if your web part interacts with actual SharePoint data sources, you’ll need to use mock data or temporary placeholders for testing.

Integrating with SharePoint Data

Navigating the vast reservoir of SharePoint data is vital in ensuring that businesses can access, utilize, and manage the data efficiently. With the SharePoint Framework (SPFx), this process becomes much more streamlined. Let’s explore the primary tools at your disposal:

  1. Using the SharePoint REST API and Microsoft Graph

The SharePoint REST API and Microsoft Graph act as doorways into SharePoint and the wider Microsoft 365 ecosystem. They provide access to diverse datasets, including lists, documents, user profiles, calendar events, and more.

SharePoint REST API: Primarily focuses on SharePoint-specific data. You can retrieve lists, library items, and even user-specific data. It’s a go-to for most SharePoint-centric operations.

Microsoft Graph: The crown jewel of Microsoft 365 integrations. It offers a unified endpoint to tap into data across various Microsoft 365 services, including SharePoint, Teams, OneDrive, and more. It’s expansive and provides more holistic data access across the Microsoft ecosystem.

2. Utilizing PnPjs

Patterns and Practices JavaScript library, or PnPjs, is an effort to standardize and simplify the way developers interact with SharePoint and Microsoft 365 data. It’s a consolidation of best practices, patterns, and helper functions that save developers time and reduce redundancy.

It provides:

  • Simplified Syntax: Accessing data becomes more intuitive, and developers can reduce the lines of code they write for common tasks.
  • Consistency and Best Practices: Adopting PnPjs means you’re aligning with tried and tested patterns recognized by the community.
  • Active Community: PnPjs has the backing of an active developer community. This ensures the library is continuously updated, improved, and aligned with SharePoint’s evolution.

3. Handling Authentication and Permissions

  • Seamless Authentication: One of the primary attractions of SPFx is its hassle-free approach to authentication. When a component needs to access data, the framework takes care of authentication, making it a smooth process for developers.
  • Permissions & Security: The SPFx operates within the context of the current user. This ensures that any data interactions respect SharePoint’s native permission model. If a user doesn’t have access to certain data within SharePoint, they won’t access it via an SPFx component either.
  • Further Control with Azure AD: For advanced scenarios or accessing broader Microsoft 365 datasets via Microsoft Graph, Azure AD comes into play. It offers a detailed permission model, allowing developers to specify the exact nature and scope of data access their solutions require.

Conclusion

SPFx’s foundation is grounded in modern development practices, making it not just a valuable asset but a necessity for businesses aiming to harness the power of SharePoint fully. From its historical underpinnings to the hands-on approach in crafting custom solutions, SPFx reveals a pathway that is both progressive and deeply integrated with the SharePoint ecosystem.

Developers, whether they’re veterans in the SharePoint arena or newcomers eager to dip their toes into its vast capabilities, will find SPFx an indispensable ally. The framework not only simplifies tasks and integration challenges but also ensures that security and SharePoint performance are at the forefront. With the tools and knowledge provided in this guide, the journey to mastering SPFx becomes more navigable and fruitful.

--

--

AllianceTek Inc.

Custom software &IT business solutions provider company US, 14 years’ experience in building mobile, cloud & web solutions - https://www.alliancetek.com