Browse Source

Video 1.7: escape hatches (debug webpack.config.js).

Frederic G. MARAND 4 years ago
parent
commit
af7d9f7e66
2 changed files with 11 additions and 2 deletions
  1. 4 1
      package.json
  2. 7 1
      webpack.config.js

+ 4 - 1
package.json

@@ -16,7 +16,7 @@
   "main": "index.js",
   "name": "starting-out-right",
   "scripts": {
-    "build": "webpack",
+    "build": "node ./node_modules/webpack/bin/webpack.js",
     "build:dev": "yarn build --env.env=dev",
     "build:dev:bundleanalyze": "yarn build:dev --env.addons=bundleanalyze",
     "build:dev:bundlebuddy": "yarn build:dev --env.addons=bundlebuddy",
@@ -28,6 +28,9 @@
     "build:watch": "yarn build --watch",
     "build:watch:dev": "yarn build:watch --env.env=dev",
     "build:watch:prod": "yarn build:watch --env.env=prod",
+    "debug": "node --inspect-brk ./node_modules/webpack/bin/webpack.js",
+    "debug:dev": "yarn debug --env.env=dev",
+    "debug:prod": "yarn debug --env.env=prod",
     "webpack-defaults": "webpack-defaults"
   },
   "version": "1.0.0"

+ 7 - 1
webpack.config.js

@@ -23,7 +23,13 @@ const addons = addonsArg => {
 // Export a function returning config instead of a static config.
 // The purpose is to allow use of the environment.
 module.exports = (env = defaultEnv) => {
-  console.log(env);
+  if (!env || !env.env) {
+    throw new Error(
+      "You must pass an -env.env flag into your build for webpack to work"
+    );
+  }
+
+  console.log("Env: ", env);
   const envConfig = require(`./build-utils/webpack.${env.env}`);
 
   // The rightmost overwrites (merges into) its left sibling.