.gitignore for CloudFlare Static Site

I used this command to make a project per Cloudflare instructions: npm create cloudflare@latest -- mysite-tld And I chose the Hello World Example with Static Site template using Git. No .gitignore file was created, so I'm trying to figure out what should be in there... 1) One person suggested that node_modules/ goes in for sure, so I have that. But still I have 9 entries that show as Modified. They are entries like node_modules\.bin (acorn and etc) that I can't seem to ignore. 2) What else should go in the file? .vscode? .wrangler? .git? 3) I gather I don't ignore package.json, package-lock.json and wrangler.jsonc?
15 Replies
Andrei Jiroh
Andrei Jiroh•3mo ago
1. Try using the Node.js gitignore from GitHub: https://github.com/github/gitignore/blob/main/Node.gitignore (if you accidentally commited the entire node_modules folder, you might need to edit your git history to nuke them) 2. .wrangler/ directory for me, although you may opt to ignore .vscode and other IDE-specific config folder/files if you don't want to share workspace configs to anyone else.
GitHub
gitignore/Node.gitignore at main · github/gitignore
A collection of useful .gitignore templates. Contribute to github/gitignore development by creating an account on GitHub.
Andrei Jiroh
Andrei Jiroh•3mo ago
3. If you manage secrets at wrangler.(jsonc|toml), you better not commit that or use Secrets Store.
Nautilus
NautilusOP•3mo ago
Thanks for that help!! I scan through so many docs but they don't really mention conventions and points like you made for #3. I'm going to nuke the whole project and start over for a couple reasons. I have one other issue which that may not correct, I have 9 items in node_modules\.bin which list as Modified but I can't seem to ignore or stage them. What should I do about these? For a better look: https://imgur.com/a/i-goofed-up-git-GDXAPnS
Razboy20
Razboy20•3mo ago
Basically, you have the problem that since node_modules was committed once already, then tracked files are still being tracked Take a look at this stack overflow post to help resolve that: https://stackoverflow.com/a/50675909 #3 convention is more coming from nodejs/javascript land, and less from Cloudflare (I.e. which files do you need to be tracked in git)
Nautilus
NautilusOP•3mo ago
Hi Raz! Yea the project has 'already committed' issues, which is one reason I will nuke it and start over. I'm trying to learn to do this clean from step 1. It's those weird 9 in node_modules\.bin that I need to make sure don't crop up again. Those aren't files but more like symlinks. I'm not sure how to .gitignore them.
Razboy20
Razboy20•3mo ago
If you have node_modules within .gitignore before node_modules is added, then nothing inside node_modules should end up in git. So if you go about this by nuking the git history, and starting over, you should be fine! gitignore is recursive
Nautilus
NautilusOP•3mo ago
Ok, yea, that makes sense. I will give it a go. Thanks for the feedback!
Razboy20
Razboy20•3mo ago
Np; additionally, with these kinds of small "tribal-knowledge" things, I would recommend asking an LLM, as they're simple and common issues with lots of replication across the internet (one of those cases where it's really useful to point you in the right direction)
Nautilus
NautilusOP•3mo ago
I was trying, but having trouble narrowing in on my question
Razboy20
Razboy20•3mo ago
hm yeah, maybe still a bit to go :sunglas:
Nautilus
NautilusOP•3mo ago
Thanks again 🙂
Razboy20
Razboy20•3mo ago
Just to elaborate on #3 a bit more then, you want to commit package.json so npm knows what dependencies you have (and other metadata), and package-lock.json so that npm knows exactly which versions you have, so that future clones have the same dependency tree. wrangler.jsonc is similar, in that it describes the metadata for your wrangler/workers project
Nautilus
NautilusOP•3mo ago
ok commit the package files, but I thought due to secrets (though I don't currently have any) I should .gitignore the wrangler. file. Hmm.
Razboy20
Razboy20•3mo ago
Cloudflare Docs
Environment variables
You can add environment variables, which are a type of binding, to attach text strings or JSON values to your Worker.
Nautilus
NautilusOP•3mo ago
Ah, secrets shouldn't be there. That's all I need to know for now. Thanks.

Did you find this page helpful?