public/.gitignore
*.js
js/app.js
mix-manifest.json
personally I added everything in gitignore
We build an app with 4 developers. We use laravel with mix to compile js and scss. Problem is, that everytime i pull the new version from github, I get merge conflicts, because I have compiled it just before and the new version from github has also a new compiled version. Same with the file mix-mainfest.json in public.
What is the best workaround for this. Or should we put the public directory in gitignore and compile on stage/prod. server? I'm scared that we will run into the problem, that we think it works, but wont because a package is wrong or something else.
@Pixelairport Building assets is a CI step. So yes, the generated assets should be Git-ignored, otherwise you’re just going to be constantly fighting conflicts.
In my applications, I have public/css/.gitignore and public/js/.gitignore files with the following content:
*
!.gitignore
That ignores all contents of those directories, expect for the .gitignore file itself.
When I deploy, I then run npm run production to build the assets for that deployment.
This means that only the sources are in your repository. Developers can run npm run dev or npm run watch on their machines, and servers run npm run production to build the assets for production (so minify, create source maps, etc) when deploying.
As @sergiu17 mentioned, you probably want to Git-ignore the public/mix-manifest.json file as well, as this can result in unnecessary diffs if the order of the files change, or if you use versioning resulting in the cache-busting query string constantly changing.
So, your next steps should be:
git rm -f --cached public/css/*.css
git rm -f --cached public/js/*.js
git rm -f --cached public/mix-manifest.json
echo "*\n.gitignore" >> "public/css/.gitignore"
cp public/css/.gitignore public/js/.gitignore
git add public
git commit -m "Stop tracking compiled assets"
This will remove the compiled CSS and JavaScript files from your Git index (but not your computer), and any future changes to these files will no longer be tracked by Git or pushed to your remote repository.
Please or to participate in this conversation.