Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
eleventhaus opened this issue Sep 30, 2024 · 0 comments

Comments

@eleventhaus
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant