The SharePoint Framework (SPFx) has become and extremely important part of Web Part development and Modern Site (Team Site, Communication Site) design. It eases development of Web Parts and extensions and our work with SharePoint data. It features user-friendly tools and extensions. SPFx allows us to develop both for SharePoint Online and on-prem (SharePoint 2016 Feature Pack 2).
To create a SPFx project, we need the Yeoman generator, which installs the packages, modules and tools that are necessary for the development, functioning and testing of the project. We run it with the yo@microsoft/sharepoint command. Besides all the mandatory elements, we can also install the KnockoutJS and ReactJS frameworks. All other componets, such as jQuery, must be installed later.
To ease project development, the PnP (Patterns and Practices) team have created a new generator: @pnp/generator-spfx. This is an open-source solution based on the classic Microsoft SPFx Yeoman generator (@microsoft/generator-sharepoint version 1.6.0) with added functions, frameworks and plug-ins, that are downloaded during the project installation.
To use the generator, we must first install it globally. We do this by running npm install-g @pnp/generator-spfx (if we are using Yarn, the command is: yarn install global @pnp/generator-spfx; if we are using pnpm, the command is: pnpm install global-pnpmfile @pnp/generator-spfx).
In contrast with the regular generator (yo @microsoft/sharepoint), we create a new project with the yo @pnp/spfx command. This command runs the PnP SPFx Yeoman generator for a new project and allows us to choose a custom configuration, which download additional modules during installation. Besides the aforementioned KnockoutJS and ReactJS, we can also select HandlebarsJS and VueJs. In the future, they will also add Angular and others. After selecting a framework, we also have the option to select various plug-ins.
The generator greatly simplifies the creation of a project and replaces the process of installing additional modules and plug-ins later on. But if this generator isn’t the right one for us, we can make our own generator, that will fulfill our specific needs.