Fetch a single SPFx sample from pnp/sp-dev-fx-webparts and pnp/sp-dev-fx-extensions without cloning the entire repo.
This CLI supports two download strategies:
- Git (recommended): partial clone + sparse checkout (fast + best for contributors)
- API (tokenless fallback): downloads only the sample files via GitHub APIs (no git required)
- Node.js: >= 18
- Git (for
--method git/ defaultautowhen git is installed): Git >= 2.25 (for sparse checkout cone mode)
Run without installing:
npx @pnp/spfx-sample get react-hello-worldOr install globally:
npm i -g @pnp/spfx-sample
spfx-sample get react-hello-worldspfx-sample get <sample-folder> [options]Examples:
# Fetch a sample into ./react-hello-world (default)
spfx-sample get react-hello-world
# You can also include "samples/" prefix
spfx-sample get samples/react-hello-world
# Pick a branch/tag/commit
spfx-sample get react-hello-world --ref main
# Choose destination
spfx-sample get react-hello-world --dest ./my-sample
# Overwrite existing destination
spfx-sample get react-hello-world --force
# Download a sample from a different repo
spfx-sample get jquery-application-toastr --repo sp-dev-fx-extensions
spfx-sample get BasicCard-CardComposition --repo sp-dev-fx-acesDefaults (unless overridden):
--owner pnp--repo sp-dev-fx-webparts--ref main
- Uses git if git is available
- Otherwise falls back to api
spfx-sample get react-hello-world --method autoUses partial clone + sparse checkout to fetch only the selected sample content.
spfx-sample get react-hello-world --method gitTokenless fallback (no git required). Downloads only the files under the sample folder.
spfx-sample get react-hello-world --method apiNote: GitHub’s anonymous API has rate limits (typically 60 requests/hour per IP). If you hit rate limits, use the git method.
- Fetches the sample
- Writes only the sample contents to
--dest - No
.gitfolder
spfx-sample get react-hello-world --mode extract- Creates a sparse git working copy in
--dest - Leaves
.gitintact so you can branch/commit/PR - Sample is located at:
dest/samples/<sample-folder>
spfx-sample get react-hello-world --mode repo --method git --dest ./work
cd ./work
git checkout -b my-change
--mode reporequires--method git(API mode cannot create a git repo).
npm cinpm run buildnode dist/cli.js --help
node dist/cli.js get react-hello-worldnpm run build
npx --no-install . --help
npx --no-install . get react-hello-worldnpm run build
npm link
spfx-sample --help
spfx-sample get react-hello-worldUnlink later:
npm unlink -g @pnp/spfx-samplenpm run build
npm packThis creates a .tgz file. In a clean folder:
mkdir ../spfx-sample-test
cd ../spfx-sample-test
npm init -y
npm i ../path/to/<the-tgz-file>.tgz
npx spfx-sample --help
npx spfx-sample get react-hello-worldThis repo uses semantic-release, which determines version bumps from Conventional Commits.
Use commit messages like:
feat(cli): add --method api fallback→ minorfix(git): handle sparse checkout edge case→ patchfeat!: change default command behavior→ major- Include
BREAKING CHANGE:in the commit body to force a major bump
If you don’t use feat:/fix: (or another release-triggering type), no release will be published.
Publishing happens automatically from main:
- Merge PR(s) into
main - GitHub Actions runs the Release workflow
semantic-release:- calculates next version from commits
- updates
CHANGELOG.md - creates a GitHub Release + tag
- publishes to npm as
@pnp/spfx-sample
- Do not manually edit
versionfor releases. semantic-release controls it. - Scoped packages must be published as public — this repo uses
publishConfig.access = "public".
To see what semantic-release would do:
npm run release:dry- GitHub repo:
pnp/spfx-sample-cli - npm package:
@pnp/spfx-sample - CLI command:
spfx-sample