GoogleChrome / GoogleChrome/workbox

Why is workbox writing files to tmp/build instead of public on deployment?

Open
#3,358 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
13k
Forks
880
Avg merge
2h 44m
Merged PRs (30d)
8

Description

If I run my build script locally, workbox writes files to the public directory:

```
> react-scripts build && workbox generateSW workbox-config.js

Creating an optimized production build...
Compiled successfully.

File sizes after gzip:

405.84 kB build/static/js/main.0a2b00bf.js
2.63 kB build/static/js/685.d490ac7a.chunk.js
831 B build/static/js/91.541a4e54.chunk.js
811 B build/static/js/153.7aa0b5d4.chunk.js
806 B build/static/js/832.8de07afe.chunk.js
733 B build/static/js/844.63deabe8.chunk.js
728 B build/static/js/580.d7932d4f.chunk.js

The project was built assuming it is hosted at /.
You can control this with the homepage field in your package.json.

The build folder is ready to be deployed.
You may serve it with a static server:

npm install -g serve
serve -s build

Find out more about deployment here:

https://cra.link/deployment

Using configuration from /root/workbox-config.js.
The service worker files were written to:
• /root/public/sw.js
• /root/public/sw.js.map
• /root/public/workbox-74969ce0.js
• /root/public/workbox-74969ce0.js.map
The service worker will precache 7 URLs, totaling 177 kB.
```

But during deployment, workbox writes the files to the tmp directory:

```
remote: > react-scripts build && workbox generateSW workbox-config.js
remote:
remote: Creating an optimized production build...
remote: Compiled successfully.
remote:
remote: File sizes after gzip:
remote:
remote: 405.84 kB build/static/js/main.0a2b00bf.js
remote: 2.63 kB build/static/js/685.d490ac7a.chunk.js
remote: 831 B build/static/js/91.541a4e54.chunk.js
remote: 811 B build/static/js/153.7aa0b5d4.chunk.js
remote: 806 B build/static/js/832.8de07afe.chunk.js
remote: 733 B build/static/js/844.63deabe8.chunk.js
remote: 728 B build/static/js/580.d7932d4f.chunk.js
remote:
remote: The project was built assuming it is hosted at /.
remote: You can control this with the homepage field in your package.json.
remote:
remote: The build folder is ready to be deployed.
remote: You may serve it with a static server:
remote:
remote: npm install -g serve
remote: serve -s build
remote:
remote: Find out more about deployment here:
remote:
remote: https://cra.link/deployment
remote:
remote: Using configuration from /tmp/build_b798eb87/workbox-config.js.
remote: The service worker files were written to:
remote: • /tmp/build_b798eb87/public/sw.js
remote: • /tmp/build_b798eb87/public/sw.js.map
remote: • /tmp/build_b798eb87/public/workbox-74969ce0.js
remote: • /tmp/build_b798eb87/public/workbox-74969ce0.js.map
remote: The service worker will precache 7 URLs, totaling 177 kB.
```

package.json

```
{
...
"scripts": {
"build": "react-scripts build && workbox generateSW workbox-config.js",
}
...
}
```

workbox-config.js:

```
module.exports = {
globDirectory: "public/",
globPatterns: ["**/*.{png,html,js,ico,json,txt}"],
swDest: "public/sw.js",
ignoreURLParametersMatching: [/^utm_/, /^fbclid$/],
runtimeCaching: [
{
urlPattern: /api/,
handler: "StaleWhileRevalidate",
options: {
cacheName: "my-api-cache",
expiration: {
maxEntries: 5,
maxAgeSeconds: 60,
},
},
},
],
};
```

file structure:

```
root
├── src
├── package.json
└── workbox-config.js
```

I have tried moving the workbox script to the heroku-cleanup script but that doesn't work. Same thing happens.

How do I get the workbox script to write to the files to the root directory on heroku?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.