Angular JS + Laravel 4: How to compile for production mode?

一笑奈何 提交于 2019-12-04 19:31:12
  • First install latest laravel in your localhost. See doc.
  • Assuming you have completed composer install command.
  • Then move your all public folder contents to the project root.
  • Next change the line 21 in index.php from,

    require __DIR__.'/../bootstrap/autoload.php'; 
    

    to

    require __DIR__.'/bootstrap/autoload.php'; 
    

    and line 35 content

    $app = require_once __DIR__.'/../bootstrap/start.php';
    

    to

    $app = require_once __DIR__.'/bootstrap/start.php';
    

    Now you can access project without public folder.

  • Place your css, js and other assets folder in root like http://localhost/laravel/css
  • Note that the laravel blade and angular also using {{ syntax for compilation.So you need to change the laravel blade syntax to {= and =}.Otherwise you will get conflict.
  • To do this open vendor/laravel/framework/src/Illuminate/View/Compilers/BladeCompiler.php file and change line 45 to this

    protected $contentTags = array('{=', '=}');
    

    and line 52 to this

    protected $escapedTags = array('{={', '}=}');
    

    Now you can use {{ for angular and {= for blade.

  • For linking your assets, use HTMLBuilder functions, see doc here.
  • Now use these in blade,

     {= HTML::style('css/style.css') =} // links localhost/project/css/style.css
    
     {= HTML::script('js/jquery.js') =}
    
  • Use migrations and db seeds in localhost and make an exported copy of db for online hosting

  • After completing project, copy entire project content to online server and change db configuration and import database.

Directory Structure for Online

There will be a public directory for your file hosting, where you put your files in web root.

That may be htdocs or public_html and now it's your project public root.Now the directory structure will be,

-- app

-- bootstrap

-- css

-- images

-- js

-- vendor
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!