Skip to content

Commit f37690f

Browse files
committed
Add custom filepath and name for generated service worker
1 parent d64a7b9 commit f37690f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

packages/react-scripts/config/webpack.config.prod.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const shouldUseRelativeAssetPaths = publicPath === './';
3535
const publicUrl = publicPath.slice(0, -1);
3636
// Get environment variables to inject into our app.
3737
const env = getClientEnvironment(publicUrl);
38+
// Get packageName from package.json
39+
const packageName = require(paths.appPackageJson).name;
3840

3941
// Assert this just to be safe.
4042
// Development builds of React are slow and not intended for production.
@@ -311,7 +313,7 @@ module.exports = {
311313
// If a URL is already hashed by Webpack, then there is no concern
312314
// about it being stale, and the cache-busting can be skipped.
313315
dontCacheBustUrlsMatching: /\.\w{8}\./,
314-
filename: 'service-worker.js',
316+
filename: `service-worker-${packageName}.js`,
315317
logger(message) {
316318
if (message.indexOf('Total precache size is') === 0) {
317319
// This message occurs for every build and is a bit too noisy.

0 commit comments

Comments
 (0)