Run Your Build

If we run the webpack command directly, we need to set up the path to the webpack executable and look up the right command-line options every time we run the build. Instead, we will create an entry in the scripts section of package.json that describes the build command, so we’ll be able to build the project with the correct options by typing only npm build.

Before we create the build command, we need to install a utility called cross-env to set environment variables in a way that works both for Windows and Unix systems:

 $ ​​npm​​ ​​i​​ ​​--save-dev​​ ​​cross-env

Once you’ve downloaded cross-env, open package.json, and in the scripts section, create a new entry to run the build. When it installs an executable, npm places the ...

Get React for Real now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.