title: React - PUBLIC_URL is still undefined after setting it
body: <p>I try to setup my PUBLIC_URL for my serviceworker configuration and befor bundling the app I set my PUBLIC_URL in the webpack.config.js:</p>
  <h3>webpack.config.js</h3>
  <pre><code>module.exports = (env) =&gt; {
  
      const isProduction = env.production === true;
      const isDevelopment = env.development === true;
  
      process.env.NODE_ENV = isProduction ? 'production' : isDevelopment &amp;&amp; 'development';
      process.env.PUBLIC_URL = '/';
  
      return {...config}
  }
  </code></pre>
  <p>I even created a <code>.env</code> file with <code>PUBLIC_URL=/</code> but nothing seems to work when I log the PUBLIC_URL in my service.worker register it is still undefined:</p>
  <pre><code>export function register(config) {
      console.log(process.env.PUBLIC_URL)
  
      if (process.env.NODE_ENV === 'production' &amp;&amp; 'serviceWorker' in navigator) {
          const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
          if (publicUrl.origin !== window.location.origin) {
              return;
          }
  
          window.addEventListener('load', () =&gt; {
              const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
  
              if (isLocalhost) {
                  checkValidServiceWorker(swUrl, config);
                  navigator.serviceWorker.ready.then(() =&gt; {
                      console.log(
                          'This web app is being served cache-first by a service worker.');
                  });
              } else {
                  registerValidSW(swUrl, config);
              }
          });
      }
  }
  </code></pre>
  <p>I am trying to run the app with the webpack-dev-server and also tried it by generating the dist folder and openend the index.html folder up. Does anyone know the reason why?</p>