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 dev. 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?
.gitignore
the js and css files and run npm on the production server to compile the assets locally?What are your thoughts on this?
Thanks in advance.
mix. js('resources/js/app. js', 'public/js');
Laravel Mix is a tool for compiling and optimizing assets in a Laravel app. It's similar to a build tool like gulp, Grunt and such like. it's specific to Laravel but can also be used externally as an npm package. Laravel Mix covered 80% of Webpack's use case to make compiling assets easier.
Introduction. Laravel Mix, a package developed by Laracasts creator Jeffrey Way, provides a fluent API for defining webpack build steps for your Laravel application using several common CSS and JavaScript pre-processors. . postCss('resources/css/app.
At my workplace we've .gitignore'd the css/js folders for almost a year for different projects with no issue just letting the server handle npm as part of it's build step.
And if you use yarn, it'll create a lock file which ensures you'll get the same exact js dependencies on production.
When using versioning just use the mix() helper on your script/css tags and it'll handle pointing to the correct file via the mix-manifest.json file in the public directory.
For example:
layout/app.blade.php has
<script src="{{ mix('js/app.js') }}"></script>
when you run npm mix creates the the public/mix-manifest.json file like so
{ "/js/app.js": "/js/app.{hash-example}.js" }
The only issue I've seen is with mix and using the mix()
helper it appears to only work while npm watch
is being run, which is something elixir handled fine before but mix is relatively new so it might get addressed, I myself haven't been annoyed enough to look into it since during development I always run npm run hot
which does hot reloading on any js file changes. -- Edit: this appears to be fixed now
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With