In my experience, Laravel Mix is a very useful tool for managing for assets. https://laravel.com/docs/5.6/mix
How do you manage your assets?
I am new to Laravel and need some suggestions for managing assets.
I put my unminified css files and js files under public/css and public/js and access them from blade with asset(). So, I am having trouble in compiling these assets with mix and switching from production to development mode.
Is putting unminified css and js files under public folder a bad practice?
If I put them under resources/assets, do I have to minify them every time before I test the application?
What is the best way of doing this?
Thanks in advanced!
That's an excellent question!
For development purposes you don't have to run the production mode of compiling assets. This is actually useful when you develop and have your develop tools open in the browser. When it's not minified you can easily inspect the code and see what it's doing. You can even debug your javascript!
Now to have everything compiled with production mode on production you have two options.
- Run
npn run productiononce and push that to your repository. From there you can deploy that to your server. However when you forget to run this once you will end up with unminified files on your server. So this would be a step before you go to production. - Run
npm run productionduring deployment. For example when you have deployments withdeployerorforgeyou can run commands before you put the application online. It's a good practice to do this, since you don't have these files in your project or git control. That also means no more conflicts when you work with others and need to compile things all the time. Note that you need to run npm on your production server so you also need to install that.
Conclusion: Option 1 works best for you when you work alone. When you work with others option 2 in the best!
Let me know if you have any more questions ;)
Please or to participate in this conversation.