Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

yaazel's avatar

What's the best practice for adding to git *.js files generated during development?

Hello,

I'm a newbie solo dev. My laravel vue project uses laravel mix to compile & bundle *.js files.

Everytime I run npm run dev or npm run watch close to 500+ *.js files are being generated aspublic/js/*.js & public/<md5hash>.js. They are messing up with my git commits.

They should be ignored from git repo right? But I don't know how to just exclude just these files and not exclude the files included in app.blade.php

        <script src="{{ asset('vendor/katex/katex.min.js') }}"></script>
        <script src="{{ asset('vendor/katex/contrib/auto-render.min.js') }}"></script>
        <script src="{{ asset('js/manifest.js') }}" defer></script>
        <script src="{{ asset('js/vendor-vue.js') }}" defer></script>
        <script src="{{ asset('js/vendor.js') }}" defer></script>
        <script src="{{ asset('js/app.js') }}" defer></script>
0 likes
7 replies
MohamedTammam's avatar
Level 51

In your git add

# Ignore every js file in that directory
public/js/**/*.js

# Except
!public/js/manifest.js
!public/js/vendor-vue.js
!public/js/vendor.js
!public/js/app.js
yaazel's avatar

@MohamedTammam you mean public/js/*.js right?

I mean, you mean the following right?

# Ignore every js file in that directory
/public/js/*.js

# Except
!/public/js/manifest.js
!/public/js/vendor-vue.js
!/public/js/vendor.js
!/public/js/app.js
yaazel's avatar

I have 200+ public/js/ abc_xyz_pqr_filename.js files. They aren't getting ignonred. I tried adding these lines

public/*
public/js/*.js
public/js/**/*.js

none of these are working.

Niush's avatar

@yaazel I am guessing some files were already committed and pushed. Delete all the files inside js directory, and clear the git cache with this:

git rm -r --cached public/js
git commit -m "remove build assets"
git push origin main

And, if git ignore is correct, any new files should be ignored from now on.

1 like
martinbean's avatar

@yaazel The “best practice” is not to track them with Git at all. They’re generated files. You should be running npm run prod when deploying to generate your assets on your production server.

1 like

Please or to participate in this conversation.