File tree Expand file tree Collapse file tree 4 files changed +11
-5
lines changed Expand file tree Collapse file tree 4 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ process.env.NODE_PATH = (process.env.NODE_PATH || '')
67
67
// injected into the application via DefinePlugin in Webpack configuration.
68
68
const REACT_APP = / ^ R E A C T _ A P P _ / i;
69
69
70
- function getClientEnvironment ( publicUrl ) {
70
+ function getClientEnvironment ( publicUrl , packageName ) {
71
71
const raw = Object . keys ( process . env )
72
72
. filter ( key => REACT_APP . test ( key ) )
73
73
. reduce (
@@ -84,6 +84,9 @@ function getClientEnvironment(publicUrl) {
84
84
// This should only be used as an escape hatch. Normally you would put
85
85
// images into the `src` and `import` them in code to get their paths.
86
86
PUBLIC_URL : publicUrl ,
87
+ // package.json name property.
88
+ // Used by service worker to know the name of the generated service worker.
89
+ PACKAGE_NAME : packageName ,
87
90
}
88
91
) ;
89
92
// Stringify all values so we can feed into Webpack DefinePlugin
Original file line number Diff line number Diff line change @@ -29,8 +29,10 @@ const publicPath = '/';
29
29
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
30
30
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
31
31
const publicUrl = '' ;
32
+ // Get packageName from package.json
33
+ const packageName = require ( paths . appPackageJson ) . name ;
32
34
// Get environment variables to inject into our app.
33
- const env = getClientEnvironment ( publicUrl ) ;
35
+ const env = getClientEnvironment ( publicUrl , packageName ) ;
34
36
35
37
// This is the development configuration.
36
38
// It is focused on developer experience and fast rebuilds.
Original file line number Diff line number Diff line change @@ -33,11 +33,12 @@ const shouldUseRelativeAssetPaths = publicPath === './';
33
33
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
34
34
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
35
35
const publicUrl = publicPath . slice ( 0 , - 1 ) ;
36
- // Get environment variables to inject into our app.
37
- const env = getClientEnvironment ( publicUrl ) ;
38
36
// Get packageName from package.json
39
37
const packageName = require ( paths . appPackageJson ) . name ;
40
38
39
+ // Get environment variables to inject into our app.
40
+ const env = getClientEnvironment ( publicUrl , packageName ) ;
41
+
41
42
// Assert this just to be safe.
42
43
// Development builds of React are slow and not intended for production.
43
44
if ( env . stringified [ 'process.env' ] . NODE_ENV !== '"production"' ) {
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ export default function register() {
12
12
if ( process . env . NODE_ENV === 'production' && 'serviceWorker' in navigator ) {
13
13
window . addEventListener ( 'load' , ( ) => {
14
14
// this would become service-work-hash.js
15
- const swUrl = `${ process . env . PUBLIC_URL } /service-worker.js` ;
15
+ const swUrl = `${ process . env . PUBLIC_URL } /service-worker- ${ process . env . PACKAGE_NAME } .js` ;
16
16
if ( ! navigator . serviceWorker . controller ) {
17
17
// No service worker yet
18
18
registerServiceWorker ( swUrl ) ;
You can’t perform that action at this time.
0 commit comments