Here's a basic cheat sheet for SharePoint Framework (SPFx) development, covering essential commands and steps for setting up, developing, and managing SPFx projects:
Prerequisites
- Node.js (LTS version recommended)
- Yeoman and Gulp:bash
npm install -g yo gulp
- Yeoman SharePoint Generator:bash
npm install -g @microsoft/generator-sharepoint
Setting Up a New SPFx Project
- Create a new directory and navigate into it:bash
mkdir my-spfx-webpart cd my-spfx-webpart
- Generate a new SPFx solution:
Follow the prompts to configure your project:bashyo @microsoft/sharepoint
- SharePoint Online only (latest)
- WebPart (or Extension)
- JavaScript framework (React, No framework, etc.)
Development Commands
Serve the project locally:
bashgulp serve
This opens a local workbench in your browser where you can test your web parts.
Build the project:
bashgulp build
Compiles the project and prepares it for packaging or deployment.
Bundle the project:
bashgulp bundle --ship
Creates a production-ready bundle of your project.
Package the solution:
bashgulp package-solution --ship
Generates the
.sppkg
file in thesharepoint/solution
directory, which can be uploaded to the App Catalog in SharePoint.
Additional Useful Commands
Clean the build directory:
bashgulp clean
Removes old build files.
Trust Dev Cert (needed for local HTTPS):
bashgulp trust-dev-cert
Untrust Dev Cert:
bashgulp untrust-dev-cert
Upgrade SPFx project (using the Office 365 CLI):
bashnpm install -g @pnp/cli-microsoft365 m365 spfx project upgrade --output md > upgrade-report.md
File Structure Overview
- src: Contains all source code for your web parts or extensions.
- webparts: Contains web part specific files.
- extensions: Contains extension specific files.
- config: Contains configuration files for the build process.
- sharepoint: Contains assets and deployment-related files.
- assets: Contains static assets for the project.
- solution: Contains the packaged solution file.
Useful Links
- SPFx Documentation: SharePoint Framework Documentation
- PnpJS: PnpJS Documentation
- Office 365 CLI: Office 365 CLI
gulp test
ReplyDelete