tartan's avatar

How can I manage frontend assets with laravel mix/elixir and version control (git)

I'm using Mix (this applies to Elixir as well I guess) to manage my frontend assets.

I have Mix configured to version files in production but not in development. As such, when I update assets, I get updated app.js and app.css files in dev and app.{hash}.js and app.{hash}.css files in production.

What is your advice on how to leverage this with version control?

1- Put the files in version control? If so how do I manage the assets versioning hash changes during deployment?

2- .gitignore the js and css files and run npm on the production server to compile the assets locally?

Some other solution?

What are your thoughts on this?

Thanks in advance.

0 likes
3 replies
okawei's avatar

Depends on what you want to do, but I personally build my static assets on the production server. Here's how my deployment script looks on forge:

git fetch
git reset --hard origin/master
composer install --no-interaction --no-dev --prefer-dist
php artisan migrate --force
gulp --production
bower install
php artisan view:clear
php artisan db:seed
php artisan optimize --force
EventFellows's avatar

if you use the version function that should be managed automatically.

whenever new versions are created the old files are deleted automatically. i see no reason why to exclude them from version control. laravel uses its own file to load the versioned files.

depending on your deployment workflow you would even be required to have them on git.

Cronix's avatar

Also, with the upcoming laravel-mix v1 release it won't hash the actual file names when using version() like it currently does. Like it won't create somefile.2l4k5h3lk45h34j5h.js. Instead, it creates a query string for the hash when using mix('somefile.js') in the view, which will output somefile.js?2l4k5h3lk45h34j5h.

In other words, the filename will always be somefile.js with the new versioning in mix v1.

Please or to participate in this conversation.