Laravel: Organizando os assets – Reiniciando

Os nossos arquivos CSS e Javascript devem ficar na pasta ‘resources/views/css’ e ‘resources/views/js’, respectivamente. Mas o nosso site irá ler a pasta public. Então, nós precisamos realizar algumas configurações e agora veremos como fazer isso logo abaixo:

Crie todos os seus arquivos de estilo e seus scripts dentro da pasta, não se preocupe em minimificá-los pois isso será feito pelo comando ‘run npm prod’.

Abra o arquivo ‘webpack.mix.js’ que encontra-se na raiz do nosso projeto e adicione as linhas conforme exemplo abaixo:

mix.styles(['resources/css/AdminLTE',
	    'resources/css/bootstrap-datepicker3.min.css',
	    'resources/css/bootstrap-multiselect.css',
	    'resources/css/bootstrap-treeview.min.css',
	    'resources/css/bootstrap.css',
	    'resources/css/dataTables.bootstrap.css',
	    'resources/css/datatables.css',
	    'resources/css/font-awesome.css',
	    'resources/css/home.css',
	    'resources/css/jquery.dataTables.css',
	    'resources/css/login.css',
	    'resources/css/maksoud.css'
	], 'public/css/style.css')
    .version();

Para evitar problemas com cache, utilizei o ‘.version()’ antes do fechamento do ponto-e-vírgula. Também foi necessário mudar o nosso arquivo ‘head’ com o ‘mix’ ao invés de ‘asset’.

Todos os arquivos serão compilados em apenas um que se chamará ‘public/css/style.css’. Agora precisamos chamá-lo dentro do nosso ‘resources/views/includes/head.blade.php’:

<link rel="stylesheet" href="{{ url(mix('css/style.css')) }}">

Agora vamos executar o comando que executará o nosso script e criará o arquivo ‘style.css’:

npm run prod (Caso você queira minimificar o seu arquivo)
npm run dev (Para um arquivo legível)

Ao final você receberá a seguinte mensagem:

Você pode identificar que foi adicionada a linha no arquivo ‘public/mix-manifest.json’ com uma hash como id, evitando que o cache do seu navegador não exiba as últimas modificações no seu arquivo, como no exemplo abaixo:

{
    "/css/style.css": "/css/style.css?id=c1ad17c8867a6929543f"
}

Agora devemos fazer o mesmo com o nossos arquivos Javascript. Meu arquivo ‘webpack.mix.js’ final ficará assim:

mix.styles(['resources/css/AdminLTE.css',
	    'resources/css/bootstrap-datepicker3.min.css',
	    'resources/css/bootstrap-multiselect.css',
	    'resources/css/bootstrap-treeview.min.css',
	    'resources/css/bootstrap.css',
	    'resources/css/dataTables.bootstrap.css',
	    'resources/css/datatables.css',
	    'resources/css/font-awesome.css',
	    'resources/css/home.css',
	    'resources/css/jquery.dataTables.css',
	    'resources/css/login.css',
	    'resources/css/maksoud.css'
	], 'public/css/style.css')
   .scripts(['resources/js/.js',
	    'resources/js/bootstrap.js',
	    'resources/js/bloodhound.js',
	    'resources/js/bootstrap-datepicker.js',
	    'resources/js/bootstrap-datepicker.pt-BR.min.js',
	    'resources/js/bootstrap-multiselect.js',
	    'resources/js/bootstrap-treeview.js',
	    'resources/js/dataTables.bootstrap.js',
	    'resources/js/datatables.min.js',
	    'resources/js/jquery.countdownTimer.js',
	    'resources/js/jquery.mask.js',
	    'resources/js/jquery.maskMoney.js',
	    'resources/js/jquery.min.js',
	    'resources/js/calcula-vencimento-cartao.js',
	    'resources/js/list-account-plans.js',
	    'resources/js/list-costs.js',
	    'resources/js/list-banks.js',
	    'resources/js/list-boxes.js',
	    'resources/js/list-cards.js',
	    'resources/js/list-customers.js',
	    'resources/js/list-providers.js',
	    'resources/js/list-document-types.js',
	    'resources/js/list-event-types.js',
	    'resources/js/list-movements.js',
	    'resources/js/maksoud-movements.js',
	    'resources/js/maksoud-plannings.js',
	    'resources/js/maksoud-custom.js',
	    'resources/js/maksoud-focus.js',
	    'resources/js/maksoud-mask.js',
	    'resources/js/maksoud-validaCpfCnpj.js',
	    'resources/js/maksoud-radiooptions.js',
	    'resources/js/maksoud-text.js',
	    'resources/js/maksoud-multiclick.js',
	    'resources/js/scripts.js',
	    'resources/js/typeahead.jquery.js'
	], 'public/js/scripts.js')
    .version();

Agora eu executo novamente o comando ‘npm run prod’ e recebo o seguinte retorno:

Note que o meu arquivo CSS que antes estava 212Kb agora está 299Kb, pois eu esqueci de adicionar a extensão ‘.css’ na primeira chamada em ‘resources/css/AdminLTE.css’. Tenha bastante cuidado para adicionar as extensões corretamente, pois não apresentará nenhum erro na execução, apenas não funcionará quando você chamar as funções.

O meu arquivo ‘public/mix-manifest.json’ agora está assim:

{
    "/css/style.css": "/css/style.css?id=a43f8e3522624fb43e73",
    "/js/scripts.js": "/js/scripts.js?id=ac627bafb8c3e5919275"
}

Precisamos agora atualizar o arquivo ‘resources/views/includes/footer.blade.php’ adicionando a seguinte linha:

<script  type="text/javascript" src="{{ url(mix('js/scripts.js')) }}"></script>

Esse projeto possui todo o código disponível em https://github.com/Maksoud/reiniciando e o projeto está hospedado em https://reiniciando.maksoud.dev/. Deixe seu comentário abaixo e colabore com esse projeto.

50 thoughts on “Laravel: Organizando os assets – Reiniciando”

  1. The data talked about within the post are a few of the most beneficial accessible. Gayle Carleton Ragen

  2. Very good post! We are linking to this great content on our website. Keep up the great writing. Dusty Pattie Even

  3. I think you have noted some very interesting points, thanks for the post. Rozina Hamid Thora

  4. Pretty! This has been an incredibly wonderful article. Many thanks for supplying these details. Ronny Jonah Cheffetz

  5. Pretty! This was an extremely wonderful post. Many thanks for supplying this information. Gerry Claudius Dorweiler

  6. This is my first time pay a visit at here and i am genuinely impressed to read all at alone place. Daloris Timoteo Garett

  7. You should be a part of a contest for one of the most useful sites online. I will highly recommend this website! Darya Francisco Bradeord

  8. Hi colleagues, its wonderful paragraph regarding teachingand completely defined, keep it up all the time.

  9. Link exchange is nothing else except it is just placing the other person’s
    web site link on your page at suitable place and other person will also
    do similar for you.

  10. Excellent blog here! Additionally your site loads up very fast!
    What host are you using? Can I get your affiliate link for your host?
    I wish my website loaded up as quickly as yours lol

  11. Please bring the continuation of the nice posts, I will be glad if you approve the comment.

  12. Thank you for informing, success is in your hands, escort I would be glad if you support me.

  13. Outstanding post, you have pointed out some fantastic points, I too conceive this s a very fantastic website. Audy Deck Law

  14. Fabulous, what a blog it is! This webpage provides helpful facts to us, keep it up. Lebbie Shelton Orlene

  15. Good post. I be taught something more difficult on totally different blogs everyday. It’ll at all times be stimulating to read content material from other writers and practice just a little something from their store. I抎 want to use some with the content on my blog whether or not you don抰 mind. Natually I抣l provide you with a hyperlink in your web blog. Thanks for sharing.

  16. You must participate in a contest for among the best blogs on the web. I’ll advocate this site!

  17. If some one wishes to be updated with most recent technologies afterward he must be pay a
    visit this website and be up to date every day.

  18. I have to voice my affection for your generosity supporting those who must have help with this one field. Your very own dedication to passing the solution across became extremely helpful and has frequently made employees just like me to get to their endeavors. Your entire interesting information signifies a whole lot to me and extremely more to my peers. Thanks a lot; from all of us.

  19. My wife and i ended up being so fulfilled that John could round up his analysis by way of the ideas he gained through your web site. It’s not at all simplistic just to be giving away concepts which people might have been selling. And we know we now have the writer to give thanks to for this. These illustrations you made, the simple web site navigation, the friendships your site help create – it’s got many unbelievable, and it is aiding our son and

  20. I really wanted to write a simple comment to be able to thank you for these fantastic strategies you are placing here. My extended internet lookup has now been honored with sensible content to exchange with my co-workers. I ‘d assume that many of us readers actually are quite fortunate to dwell in a really good website with very many brilliant people with insightful pointers. I feel truly privileged to have used your entire web page and look forward to many more awesome moments reading here. Thanks again for everything.

  21. I’m commenting to let you understand of the really good experience our child undergone visiting yuor web blog. She noticed a good number of issues, most notably what it’s like to possess an excellent giving mood to get others easily have an understanding of chosen impossible topics. You undoubtedly exceeded her expected results. I appreciate you for producing the powerful, trusted, explanatory and in addition easy guidance on the topic to Evelyn.

  22. Thank you for all your valuable effort on this web site. My mum take interest in making time for investigation and it’s obvious why. Most of us notice all regarding the lively method you provide great strategies on this web blog and as well inspire participation from visitors on this area of interest and my simple princess is undoubtedly understanding a great deal. Have fun with the rest of the year. You have been performing a really great job.

  23. I needed to draft you a little remark in order to thank you so much the moment again regarding the great advice you have shown in this case. It is certainly seriously generous with you to deliver publicly all numerous people might have offered for sale as an e-book to end up making some dough for their own end, specifically considering that you could have done it in the event you desired. These principles additionally acted to become a great way to fully grasp other individuals have the identical eagerness much like my own to understand significantly more when considering this issue. I think there are numerous more enjoyable opportunities in the future for those who scan through your website.

  24. I simply wanted to say thanks again. I am not sure the things I would’ve tried in the absence of the type of tips and hints shared by you over this problem. This has been a distressing crisis in my position, but coming across a specialised approach you treated it made me to jump for joy. I am grateful for your help and in addition hope that you realize what an amazing job you are always providing teaching the mediocre ones through the use of your webblog. I am certain you have never met any of us.

  25. I’m commenting to make you be aware of of the nice encounter my friend’s princess encountered browsing the blog. She discovered plenty of things, not to mention how it is like to have a great teaching character to make folks completely know some advanced subject matter. You undoubtedly did more than our expectations. Many thanks for offering these important, healthy, educational not to mention unique thoughts on your topic to Mary.

  26. I in addition to my pals have already been reviewing the good items from your web site while all of the sudden I got a horrible suspicion I had not thanked the website owner for those techniques. These young men happened to be warmed to see them and have simply been taking pleasure in these things. Appreciate your getting indeed kind and also for obtaining this sort of important useful guides most people are really wanting to be informed on. Our sincere apologies for not expressing appreciation to earlier.

  27. I as well as my guys have been following the good procedures located on your web blog then quickly got a horrible feeling I never expressed respect to the blog owner for those tips. Most of the people appeared to be as a result happy to see them and have now in reality been using these things. Appreciation for indeed being simply considerate and for going for these kinds of nice guides most people are really needing to be aware of. Our honest regret for not saying thanks to you sooner.

  28. I simply wanted to type a brief message to be able to thank you for these great guides you are giving at this site. My time-consuming internet search has at the end of the day been paid with reasonable ideas to share with my two friends. I would mention that most of us readers are very blessed to dwell in a remarkable network with so many wonderful people with valuable plans. I feel truly fortunate to have seen your webpage and look forward to tons of more amazing moments reading here. Thanks a lot once again for a lot of things.

  29. I have to convey my affection for your kind-heartedness for men who absolutely need help with the question. Your personal commitment to getting the message along turned out to be surprisingly valuable and has in most cases empowered regular people just like me to get to their ambitions. The valuable information means a whole lot a person like me and even more to my fellow workers. Warm regards; from all of us.

  30. My spouse and i got absolutely lucky when Michael managed to complete his web research while using the ideas he acquired while using the site. It’s not at all simplistic to just happen to be releasing hints the rest might have been selling. Therefore we fully understand we have the writer to give thanks to for that. The explanations you’ve made, the simple site navigation, the friendships your site make it possible to instill – it’s everything unbelievable, and it is letting our son and the family consider that the subject matter is fun, and that is tremendously pressing. Thank you for all the pieces!

  31. I happen to be commenting to let you understand what a fantastic experience my cousin’s girl enjoyed going through the blog. She picked up plenty of issues, not to mention how it is like to have an excellent teaching style to make the rest easily thoroughly grasp a number of tortuous topics. You actually exceeded my expectations. Thank you for giving such important, trusted, revealing not to mention fun tips about your topic to Lizeth.

  32. I wish to get across my passion for your kindness for people who need assistance with this area of interest. Your real dedication to getting the solution all over ended up being wonderfully functional and have frequently made those much like me to arrive at their dreams. Your amazing informative tutorial denotes this much to me and additionally to my office workers. Thank you; from each one of us.

  33. I am commenting to let you know of the great experience my princess found reading your blog. She discovered such a lot of things, not to mention what it is like to possess an ideal helping character to let many others completely completely grasp chosen hard to do topics. You really did more than readers’ desires. Thank you for delivering these powerful, safe, edifying and unique tips about that topic to Tanya.

  34. I am writing to make you understand what a magnificent encounter our daughter gained reading through your site. She discovered a lot of pieces, not to mention how it is like to possess a marvelous coaching spirit to have many people really easily know a number of advanced topics. You truly exceeded visitors’ desires. Many thanks for presenting those warm and friendly, dependable, edifying and in addition easy guidance on the topic to Julie.

  35. Hello, i think that i noticed you visited my weblog thus i got here to “go back the want”.I’m attempting to in finding issues to improve my web site!I suppose its adequate to use some of your ideas!!

  36. My spouse and i felt comfortable when Chris managed to conclude his web research via the ideas he discovered from your very own blog. It is now and again perplexing to just be releasing tips and hints people may have been trying to sell. And we all realize we now have you to thank for this. Most of the explanations you have made, the straightforward website menu, the friendships you make it possible to create – it is most superb, and it’s really assisting our son in addition to our family consider that this idea is fun, and that’s unbelievably pressing. Thank you for all the pieces!

  37. Hello there. I found your web site by way of Google whilst looking for a comparable topic, your web site got here up. It seems to be good. I have bookmarked it in my google bookmarks to visit then.

  38. I intended to write you that tiny note to help thank you once again with the stunning opinions you have discussed on this website. It is certainly generous of people like you to supply openly precisely what many people could possibly have sold as an e book to end up making some dough for their own end, particularly since you could have done it if you decided. The tactics likewise worked to become a easy way to realize that other people have a similar eagerness just as my own to find out a little more with regards to this matter. I know there are several more enjoyable times in the future for many who looked at your site.

  39. I would like to thank you for the efforts you have put in penning this website. I really hope to view the same high-grade content from you later on as well. In fact, your creative writing abilities has inspired me to get my own, personal blog now 😉

Leave a Reply