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

Fix deploy for CRA2 #155

Closed
chris48s opened this issue Feb 14, 2019 · 3 comments
Closed

Fix deploy for CRA2 #155

chris48s opened this issue Feb 14, 2019 · 3 comments
Assignees

Comments

@chris48s
Copy link
Collaborator

Currently the deploy script is broken.

The reason for this is that with react-scripts 1.x, running npm run build would spit out a single file:

File sizes after gzip:

  71.15 KB  build/static/js/main.68b0f98d.js

Then in deploy.sh we'd pick that file out and upload it to S3 as wdiv.js.

From react-scripts 2.x, running npm run build now spits out multiple files:

File sizes after gzip:

  67.04 KB  build/static/js/2.734c1cc1.chunk.js
  2.67 KB   build/static/js/main.bea25228.chunk.js
  761 B     build/static/js/runtime~main.fdfcfda2.js

but our deploy script was only uploading one of them.

This was pretty much impossible to pick up locally. I only noticed it when I deployed to production and and broke everything (side note: it has clearly been ages since I last deployed this 😳 ) . As a quick fix, I downgraded to react-scripts == 1.1.5 locally, ran a build locally and pushed that up to S3. That gets us a non-broken deploy on widget.wheredoivote.co.uk but the repo as it stands will currently break production if we try to deploy.

Fixing this is high priority.

Next steps:

  • Set up a dev S3 bucket and point a subdomain at it in CloudFront so we can deploy test builds without breaking production
  • Are there config/flags we can pass to react-scripts in order to get it to build down to a single file?
  • If not, manually work out how to deploy the multi-file version (the main thing we want to avoid here is making a breaking change for existing users. i.e: if someone has <script type="text/javascript" src="https://widget.wheredoivote.co.uk/wdiv.js"></script> in their website now, I really want to find a way ensure that stays working 🤞 )
  • Update deploy.sh as appropriate
@chris48s chris48s self-assigned this Feb 14, 2019
@mrwilson
Copy link
Collaborator

This seems to be a problem with CRA2 and there's a bunch of bug reports around it.

There is allegedly a workaround (though I haven't tried it yet):

facebook/create-react-app#5306 (comment)

@mrwilson
Copy link
Collaborator

This does seem to work:

  1. Create a build-without-chunks.js with the contents of the comment above, make it executable
  2. Install rewire (npm --save-dev ...)
  3. Replace run in package.json with node ./build-without-chunks.js

Happy to open a PR if this is an acceptable stop-gap.

@chris48s
Copy link
Collaborator Author

I'm not sure its a bug as such. Its an intentional and documented change in behaviour, but its a change in behaviour which is problematic for some use cases (including ours). But yes please - do submit a PR. I've not really put any thought into this beyond working out how to un-break prod and writing this up to come back to it. Reading that thread, if we can use that workaround that allows us to build a single file, that sounds ideal. I'd still like to set up a staging environment to test with though, so may sit open for a bit until I get a chance to do that.

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

No branches or pull requests

2 participants