Thistoolallowstoreplacesymboliclinksbyrealfilesingivendirectoryandrevertthechangesbacktosymlinks.Allthemagicinasimpleclicommand!
Installationnpminstallsymlink-resolver--save-devNode.jsv6.4+andPOSIX-standarizedoperatingsystemarerequired.
Toyourpackage.jsonscriptssectionaddthefollowingrule:
"scripts":{"symlink-resolver":"symlink-resolver",}BasicUsageForfastusageyoucansimplyrun:
npmrunsymlink-resolverbuild./symlinks/pathtoreplacesymlinksbyrealfilesin./symlinks/pathnpmrunsymlink-resolverclear./symlinks/pathtorestoreallsymlinksFirstcommandwillcreate./symlinks/path/.symlinks.jsonfilewhichcontainschangesthathavebeenmadeinthisdirectory.Itwillberemovedbythesecondcommand,howeveryoucanstilladdtoyour.gitignorethefollowingrule:.symlinks.json
Howtocreateasymlink?Useln-stargetsourcecommand,i.e.:
ln-s../../source/path/linked-dir./project/src/linked-dirAdvancedusageIfyouneedthisfeaturetomakeabuild,thenIstronglyrecommendtoautomatizeyourbuildingprocess:
"scripts":{"symlink-resolver":"symlink-resolver","prebuild":"npmrunsymlink-resolverbuild./symlinks/path","postbuild":"npmrunsymlink-resolverclear./symlinks/path","build":"yourbuildcommandshouldbeunderthisname"}Thiswayyouwillbeabletomakeabuildandedityourfileswithoutworries.
However,insomecaseslikeemulatingadevice,the"post"scriptwillnotbeexecuted.IfthisisalsoyourcasethentakealookatexampleworkaroundforNativeScript:
"scripts":{"symlink-resolver":"symlink-resolver","prens-bundle":"npmrunsymlink-resolverbuild./symlinks/path","delay-clear":"sleep22&&npmrunsymlink-resolverclear./symlinks/path","ns-bundle":"npmrundelay-clear|ns-bundle","start-android-bundle":"npmrunns-bundle--android--start-app","start-ios-bundle":"npmrunns-bundle--ios--start-app","build-android-bundle":"npmrunns-bundle--android--build-app","build-ios-bundle":"npmrunns-bundle--ios--build-app"},AdvancedconfigurationYoucanadjustConfigtoyourneeds.
Wanttousecustomsymlinksfilename?Noproblem,justsetConfig.symlinksFiletowhateveryouwant.Needsomecustombehavior?SimplyextendSymlinkHelperclassandsetConfig.helperClasstoyours.exportinterfaceConfigInterface{rootDir:string;symlinksFile:string;helperClass:typeofSymlinkHelper;}Happydeveloping!
评论