prebuild.js 732 B

1234567891011121314151617181920212223
  1. const fs = require("fs");
  2. const path = require("path");
  3. // for development purposes we want to have the service-worker.js file
  4. // accessible from the public folder. On build though, we need to compile it
  5. // and CRA expects that file to be in src/ folder.
  6. const moveServiceWorkerScript = () => {
  7. const oldPath = path.resolve(__dirname, "../public/service-worker.js");
  8. const newPath = path.resolve(__dirname, "../src/service-worker.js");
  9. fs.rename(oldPath, newPath, (error) => {
  10. if (error) {
  11. throw error;
  12. }
  13. console.info("public/service-worker.js moved to src/");
  14. });
  15. };
  16. // -----------------------------------------------------------------------------
  17. if (process.env.CI) {
  18. moveServiceWorkerScript();
  19. }