Laravel中的备用文件夹结构

时间:2017-07-29 09:41:13

标签: laravel vue.js single-page-application directory-structure

我正在Laravel中创建一个SPA应用程序,它包含一个API(在PHP中)和VueJS中的两个应用程序,一个Admin Backoffice和一个前端Web门户。

理想情况下,我想将API保存在一个单独的域中,例如 api.mydomain.com ,但是devops告诉我,这可能不是因为它会搞乱他们的CI结构,因为根据他们很难保持一切同步......

所以我被迫在同一个项目中做所有事情,现在,我不认为我的Vue Routes和东西和东西都属于Laravel翻译和Blade视图旁边的“resources”目录...... 使用“全能”路径的刀片视图意味着我无法使用 Webpack的HTML插件,我认为前端和管理员视图应该具有不同的依赖关系 webpack.config 文件。

因此。我正在尝试执行以下文件夹结构

/server
|-api (replaces the APP folder)
|
|--v1/
|---Controllers/
|---Middleware/
|---Repositories
|---Traits
|---routes.php
|--Core(Kernels)
|--Models
|--Jobs
|--Providers
|
|-bootstrap
|-config
|-database
|-resources(laravel blade views (if any) and translations)
|-storage
|-tests(phpunit)
|-composer.json

/admin
|-components
|-views
|--partials/
|-utils
|-services
|-vuex
|-App.vue
|-config.js
|-main.js
|-routes.js
|-index.html
|-package.json
|-webpack.config.js

这个想法是你总是需要通过Laravel的index.php文件路由,然后在laravel路线中我有一个全能的,它只返回Vue的 index.html 我这样做因为我需要一个简单的HTML根文件,以便能够利用 Webpack HTML插件 你们怎么看待这个想法?可行?有没有更好的方法来实现这种分离?

1 个答案:

答案 0 :(得分:0)

You don't really need to separate them on the production server. You don't even need the resources folder on the production server. All you need is the two separate js files in the public/assets/js folder and then in your index.blade.php file you can choose which js file to load based on the user's role. I don't even have node installed on any of my production servers and my app.js works just fine. Just make sure that when you compile with webpack that you run the following command:

npm run prod

Then just copy the output js file into your /project/public/assets/js folder.