SPFx Foundations: Scaffold, Project Anatomy & the Dev Loop
Lesson 3: SPFx Foundations โ Scaffold, Project Anatomy & the Dev Loop
SharePoint Framework (SPFx) is the modern model for building SharePoint customizations: your components are ordinary web assets (TypeScript compiled to JS bundles) that SharePoint's client-side runtime loads inside modern pages. No server code, no farm installs โ just a package your app catalog serves. SPFx also lets one codebase target SharePoint, Microsoft Teams tabs/personal apps, and Outlook add-ins, because the components are host-agnostic web parts underneath.
What you can build with SPFx
| Component | What it does |
|---|---|
| Client-side web part | A self-contained widget authors drag onto any page. The bread-and-butter of this course. |
| Application customizer | Code that runs on every page of a site โ injects headers/footers/scripts. |
| Field customizer | Custom rendering for a list column's cells. |
| List view command set | Custom buttons in a list's toolbar / item context menu. |
| Library component | Shared code (e.g. a common data layer) other solutions consume. |
The toolchain
SPFx development runs on Node.js with a Microsoft-maintained build toolchain (webpack underneath). One important version note: SPFx v1.22+ moved from the classic Gulp-based toolchain to a Heft-based one (Rushstack). New scaffolds use Heft; older projects (v1.0โv1.21.1) and most legacy samples still use Gulp. Commands differ slightly, and this course shows the current Heft form with the Gulp equivalent alongside.
# install the global scaffolding tool (once)
npm install -g yo @microsoft/generator-sharepoint
# scaffold a new solution in a fresh folder
yo @microsoft/sharepoint
The generator asks a few questions: your solution name, which SharePoint environment (Online, or an on-premises version if relevant), the framework you want (React or no JavaScript framework โ both are first-class; start with "no framework" to learn the mechanics), and which component type to scaffold (a web part is the default). It then produces a complete, runnable project.
nvm (macOS/Linux) or nvm-windows so each repo's .nvmrc/engines gets the right runtime. Wrong Node is the #1 cause of mysterious gulp failures.
Anatomy of a generated project
| Path | Purpose |
|---|---|
config/package-solution.json | The identity of your deployable solution: name, GUID, version, tenant-wide flags. This becomes the .sppkg. |
config/serve.json | Dev-server settings โ which workbench to open, port (default 4321). |
config/write-manifests.json, copy-assets.json, etc. | Build plumbing: asset copying and manifest emission. |
src/index.ts | Entry point that registers every component in the bundle. |
src/webparts/<name>/<Name>WebPart.ts | The web part class โ where you render. |
src/webparts/<name>/<Name>WebPart.manifest.json | Component manifest: id, title, icon, default properties, supported hosts. |
src/webparts/<name>/loc/*.js | Localized UI strings (en-us by default). |
src/webparts/<name>/<Name>WebPart.module.scss | CSS module styles scoped to your component. |
gulpfile.js (legacy) / Heft config, package.json, tsconfig.json | Build orchestration, dependencies, TypeScript config. |
The dev loop: heft start + the workbench
During development you never upload anything. You run a local build server and preview against SharePoint's workbench:
heft start # legacy gulp-based projects (SPFx v1.0-1.21.1): gulp serve
- Local workbench (default): opens the workbench on
https://localhost:4321โ your component runs isolated from a real site. The first run handles the local HTTPS certificate setup for you. - Hosted workbench: better for real data. Open
https://<your-tenant>.sharepoint.com/_layouts/15/workbench.aspxand add?debugManifestsFile=https://localhost:4321/temp/manifests.jsso the page loads your locally-served component. Your web part then renders against the real site, with real lists and permissions.
Save a file โ the dev server recompiles โ refresh the workbench. When you're happy, stop and produce the shippable package (Lesson 7):
heft build --clean --production
heft package-solution --production
# legacy gulp-based projects instead run:
# gulp clean && gulp bundle --ship && gulp package-solution --ship
That last command emits sharepoint/solution/<name>.sppkg โ the file everything downstream deploys. (Both toolsets expose these through package.json scripts too, so npm run bundle -- --ship-style invocations appear in many repos and CI files.)
๐ง Knowledge Check
1. Which command scaffolds a new SPFx solution?
2. What does heft start do in a current SPFx project?
3. Where does the hosted workbench live, and what extra query parameter makes it load your local component?