General SPFX Development time savers

%3CLINGO-SUB%20id%3D%22lingo-sub-1995737%22%20slang%3D%22en-US%22%3EGeneral%20SPFX%20Development%20time%20savers%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1995737%22%20slang%3D%22en-US%22%3E%3CP%3EI%20thought%20I'd%20share%20a%20few%20foundational%20tips%20that%20I%20wish%20I'd%20had%20from%20the%20beginning.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1)%20Install%20and%20use%20%22pnpm%22%20instead%20of%20%22npm%22%20whenever%20possible%20--%20and%20it%20has%20always%20been%20possible%2C%20in%20my%20experience.%20There%20was%20so%20much%20wasted%20disk%20space%20(and%20consequently%20%3CEM%3Etime%3C%2FEM%3E)%20to%20be%20saved%20by%20doing%20this.%20I%20was%20able%20to%20delete%20gigabytes%20and%20gigabytes%20of%20pointless%20node_modules%20directories%2C%20and%20pnpm%20replaced%20them%20with%20directory%20junctions%20managed%20from%20a%20central%20location%20in%20%25AppData%25%20or%20similar%20locations%20for%20linux%20and%20mac.%3CBR%20%2F%3EThe%20default%20'yo'%20commands%20may%20undermine%20the%20efforts%20to%20change%2C%20though.%26nbsp%3B%20Add%20%22--package-manager%20pnpm%22%2C%20and%20it%20won't%20get%20you%20off%20on%20the%20wrong%20foot%20with%20npm.%20If%20you're%20a%20bash%20user%2C%20you%20can%20prepare%20yourself%20never%20to%20forget%20that%2C%20with%20something%20like%20this%20in%20your%20.bash_profile.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3EYO%3D%24(which%20yo)%0Ayo%20()%7B%0A%20%20%20%20%24YO%20%22%24*%22%20--package-manager%20pnpm%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E2)%20Install%20and%20use%26nbsp%3B%22spfx-fast-serve%22%20which%20can%20set%20up%20a%20working%20directory%20with%20%22pnpm%20run%20serve%22%20instead%20of%20using%20%22gulp%20serve%22.%20When%20you're%20editing%20files%20and%20saving%20changes%20frequently%2C%26nbsp%3Bthe%20time%20saved%20is%20tremendous.%20%22gulp%20serve%22%20would%20normally%20load%20your%20changes%20and%20have%20the%20updated%20content%20served%20for%20your%20workbench%20pages%20within%2030-60%20seconds%2C%20but%20spfx-fast-serve%20got%20that%20down%20to%20between%203%20-%2012%20seconds.%20It%20is%20quick%20and%20easy%20to%20set%20up.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E3)%20Assuming%20you%20review%20your%20commits%20(and%20I%20recommend%20you%20do)%2C%20%22git%20diff%22%20can%20show%20you%20a%20completely%20unmanageable%20mess%20unless%20you%20create%20a%20%22.gitattributes%22%20file%20in%20your%20project%20roots.%20This%20can%20tell%20git%20to%20stop%20showing%20diffs%20for%20any%20machine%20generated%20files%20that%20are%20committed.%20Most%20git%20users%20are%20aware%20that%20the%20.gitignore%20is%20where%20you%20list%20most%20machine-generated%20content%2C%20but%20with%20node%20development%2C%20you%20aren't%20supposed%20to%20.gitignore%20the%20package-lock.json%20or%20equivalent%20files%20for%20other%20package%20managers.%20In%20my%20own%20.gitattributes%20file%2C%20I%20also%20added%20a%20line%20for%20jquery*.js%2C%20because%20of%20some%20upstream%20files%20that%20were%20committed%20with%20some%20of%20the%20sp-dev-fx-*%20samples.%3CBR%20%2F%3E.gitattributes%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-git%22%3E%3CCODE%3E*.min.*%20-diff%0Apackage-lock.json%20-diff%0Ayarn.lock%20-diff%0Apnpm-lock.yaml%20-diff%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat%20is%20something%20I%20always%20add%20to%20my%20first%20commit%20in%20a%20new%20SPFX%20project.%20If%20you%20ever%20do%20need%20to%20try%20and%20read%20through%20changes%20the%20package%20lock%20file%2C%20you%20could%20temporarily%20delete%20any%20of%20these%20lines%20from%20the%20.gitattributes%20file%2C%20and%20just%20don't%20commit%20that%20change.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20hope%20that%20helps%20somebody%20out%20there.%20Maybe%20leave%20a%20note%20if%20it%20does%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

I thought I'd share a few foundational tips that I wish I'd had from the beginning.

 

1) Install and use "pnpm" instead of "npm" whenever possible -- and it has always been possible, in my experience. There was so much wasted disk space (and consequently time) to be saved by doing this. I was able to delete gigabytes and gigabytes of pointless node_modules directories, and pnpm replaced them with directory junctions managed from a central location in %AppData% or similar locations for linux and mac.
Every 'yo' commands may undermine your time & disk savings, when it uses "npm" by default. Add "--package-manager pnpm" to your 'yo' commands to avoid wasteful executions and package installations. If you're a bash user, you can make it impossible to forget, with something like this in your .bash_profile:

 

 

 

YO=$(which yo)
yo (){
    $YO "$*" --package-manager pnpm
}

 

 

 

2) Install and use "spfx-fast-serve". When you're editing files and saving changes frequently, "gulp serve" reloads more slowly than necessary. spfx-fast-serve sets up a working directory for you to use "pnpm run serve" instead of "gulp serve". The time saved is tremendous. "gulp serve" would normally load your changes and have the updated content served for your workbench pages within 30-60 seconds, but spfx-fast-serve got that down to between 3 - 12 seconds. It is quick and easy to set up.

 

3) Assuming you review your commits (and I recommend you do), "git diff" can show you a completely unmanageable mess unless you create a ".gitattributes" file in your project roots. This can tell git to stop showing diffs for any machine generated files that are committed. Most git users are aware that the .gitignore is where you list most machine-generated content, but with node development, you aren't supposed to .gitignore the package-lock.json or equivalent files for other package managers. In my own .gitattributes file, I also added a line for jquery*.js, because of some upstream files that were committed with some of the sp-dev-fx-* samples.
.gitattributes:

 

 

 

*.min.* -diff
package-lock.json -diff
yarn.lock -diff
pnpm-lock.yaml -diff

 

 

 

 

That is something I always add to my first commit in a new SPFX project. If you ever do need to try and read through changes the package lock file, you could temporarily delete any of these lines from the .gitattributes file, and just don't commit that change.

I hope that helps somebody out there. Maybe leave a note if it does?

0 Replies