This post isn’t explanation. This is a question.
Many people say that gulp, grunt and other build systems are overkills and we should just use simple npm-scripts. That’s reasonable, but there is a problem of organizing npm-scripts.
What am I talking about? Well, here is an example of npm scripts:
As you may noticed, it’s hard to understand all of this complex commands. So when you start to use too many specific flags or agruments of your command, your npm-script became ugly.
What the solution? Unfortunately, I don’t know. However, I have some ideas.
The simplest way to make your commands a little bit simpler is using of better-npm-run package. This package give us opportunity to define environment variables in more readable way. By the way it’s cross-platform.
Here is an example:
In most of cases, the command which is used in npm-script is part of npm package. And this package should have API. It’s simple to use this API and implement what you need.
If your script require a specific system command (like
mkdir, etc), feel free to use
Another way is good when your command is really complex. Create a
scripts folder and put there shell scripts for your tasks.
The benefits of this way:
- Scripts are much more extandable
package.jsonis kept very simple
- You can define environment variables in your scripts
- You can do almost everything in your scripts
But this solution isn’t cross-platform and that’s may be a big problem.
Those solutions may be not good enough, but this is working. I will be glad to hear any other solution, because that’s exactly what I’m looking for. So if you have any better idea, please, let me know.