Where should I store JS in Laravel 5?

2019-04-24 08:08发布

There are 2 places where I can store javascripts: resources/assets/javascripts and public/js.

If we put the files in resources/assets/javascripts, we should add gulp tasks to copy them. And this is a weakness of this method. And we will need path mapping in browser debugger.

If we put these files in public/js, we will have our source JS and compiled JS in one place and they will be messed up.

So, where should I store JS in Laravel 5?

2条回答
Evening l夕情丶
2楼-- · 2019-04-24 08:47

The "Laravel-5" answer is to put them in resources/assets/javascripts. Then you use Laravel-Elixer, which is the new npm package from Taylor + Jeffrey Way that handles the entire asset management for you using gulp.

Using Laravel-Elixer, you can publish, combine, minifiy and version control all your css + js assets in a simple workflow.

Elixer does alot more - you can read about it here: https://github.com/laravel/elixir

Jeffrey Way has also done a whole Laracast series on it (which I think this series is free): https://laracasts.com/index/elixir

查看更多
干净又极端
3楼-- · 2019-04-24 08:57

Found my old question and decided to answer myself.

In 2018 it's better to split the system into many separate projects: backend, frontend, iOS app, Android app, etc.
And each app may have its own build system, directory structure, etc.

查看更多
登录 后发表回答