DEV Community

Fernando B 🚀
Fernando B 🚀

Posted on

Save time and disk space for node projects

Do you like saving time, and precious disk space when working on npm projects? If the answer is yes, then this post is for you.

Recently I have been learning electron, and react-electron. One huge problem when setting up these types of projects is the overhead of setting up a few files, and then waiting for tons of package installs. If you don't believe try this template https://github.com/electron-react-boilerplate/electron-react-boilerplate. Check your disk size prior to npm install, and afterwards. Also time how long it takes.

  • Original size after git clone 4MB
  • yarn (30seconds, I had to install yarn, above repo is really picky about npm)
  • 635MB size after installing packages

PNPM for installing packages

If you don't know about pnpm, it has a global store, then when you do pnpm install lodash it creates a linked directory in node_modules, but the package is not re-downloaded thirty million times. Only once, and then later on when you want to update it.

https://pnpm.js.org/

That along will save you tons of space, but wait there is more.

Creating projects with a shell function

On my ~/git directory, I have two templates I use quite often.

  • electron-app-template
  • cra-electron-template

You can make any project you'd like, set it up how you want it. Make sure it runs on dev, production, build, etc. When you are happy with your template, add a function to bash or in my case fish:

Fish create-electron-app.fish inside ~/.config/fish/functions

function create-electron-app --argument dir
    mkdir $dir
    cp -RT ~/git/electron-template $dir
end
Enter fullscreen mode Exit fullscreen mode

From the command line I can run the following to create a new project in a split second:

$ create-electron-app fab-project
Enter fullscreen mode Exit fullscreen mode

Bash (Create this function whatever you put your functions):

create-electron-app(){
    mkdir $1
    cp -RT ~/git/electron-template $1
}
Enter fullscreen mode Exit fullscreen mode

I hope you enjoyed this post, and let me know what other saving time, and disk space you have in your repertoire. Thanks for reading!

Top comments (1)

Collapse
 
thefern profile image
Fernando B 🚀

You're welcome, to be honest I didn't know until pnpm until recently.