April 07, 20182 min read
Run your webpack builds from scripts

You might have used webpack already. For you, webpack is that tool that runs from the commandline and builds your project. Also you might have come to that point, where your npm build commands looked like a mess. They were extremly long and did a lot of things.

What to do?

So what can we do about that?

It's simple. We will take a hybrid approach. We will combine the scripting like in grunt/gulp with webpack!

So instead of doing this:

  "scripts": {
    "build": "webpack --config config/webpack.prod.config.js"

We can execute this from a script:

"use strict";
process.env.NODE_ENV = "production";

const webpack = require("webpack");
const config = require("../config/webpack.prod.config.js");

const compiler = webpack(config);
compiler.run((err, stats) => {
  // do some error/stats printing here
  "scripts": {
    "build": "node ./build/build.js"

That was simple, wasn't it?

And it is even documented: Docu

And because we can run this config from code, we can now even build shareable webpack build configs! How to share your build config

So I want to start a little revolution with you! The revolution to fight long npm build commands. Let's create build scripts instead!

Please help me spread the word by sharing this article.

Wanna now more?