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:

	], 'public/css/style.css')

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:

	], 'public/css/style.css')
	], 'public/js/scripts.js')

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 e o projeto está hospedado em Deixe seu comentário abaixo e colabore com esse projeto.

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

  1. 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.

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

  3. 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.

  4. 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.

  5. 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

  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. 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.

  11. 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.

  12. 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.

  13. 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.

  14. 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.

  15. 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.

  16. 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!

  17. 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.

  18. 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.

  19. 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.

  20. 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.

  21. 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!!

  22. 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!

  23. 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.

  24. 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.

  25. 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