facebook/create-react-app

Add flexibility to the start script

license2e opened this issue · 2 comments

Description

Instead of just calling openBrowser, allow developers to pass in a script to kick off the start or open functionality. For example, this would be useful for use with electron development.

Proposed behavior

Inside: packages/react-scripts/scripts/start.js

@@ -279,7 +279,15 @@ function runDevServer(host, port, protocol) {
     console.log();

     if (isInteractive) {
-      openBrowser(protocol + '://' + host + ':' + port + '/');
+      var devUrl = protocol + '://' + host + ':' + port + '/';
+      var startScriptPath = require(paths.appPackageJson).startScript || false;
+      if (startScriptPath) {
+        var path = require('path');
+        process.env.DEV_URL = devUrl;
+        require(path.join(process.cwd(), startScriptPath));
+      } else {
+        openBrowser(devUrl);
+      }
     }
   });
 }

Thoughts?

I think #873 (and #1148) should cover this. It's not exactly the same solution but I think we can close this as a duplicate of #873.

👍 Thank you!