12

Using latest angular-cli, I created new project and everything works fine. Next, I tried to integrate it in Laravel 5.3. I have this project working with systemjs, but I want to switch to webpack and to take advantage of angular-cli.

Problem is that in angular-cli.json I can't specify that index is index.php, it only accepts HTML.

Basically, I can't start the Angular application at all with this setup.

How can I overcome this?

3
  • 4
    I'm working with angula2, angular-cli and laravel 5.3, but i keep them apart, I build an API with laravel and consume it with angular2 and it work well, why dont you use the same approach? Commented Nov 26, 2016 at 21:24
  • @CristianSepulveda Thank you for the input (y) Commented Dec 29, 2016 at 12:42
  • @CristianSepulveda can u please provide any url demo for strutured u are using, I also want this but with laravel want to install angular 4 Commented Jun 7, 2017 at 10:04

5 Answers 5

9

In the end I separated Laravel and Angular 2, as Cristian Sepulveda wrote in the comment. This is the recommended approach anyway.

I make API with Laravel and use it with Angular 2.

Sign up to request clarification or add additional context in comments.

1 Comment

How can I make API in Laravel to use it?
3

In my case I serve the angular app from laravel. I still use webpack to build my assets but have a gulp task which copies the angular index.html to be index.blade.php of which the laravel app serves. I also use gulp to copy the built files from /dist to /public

Comments

0

I had the same problem and what I found is this related issue in their GitHub issues:

The output folder will always be entirely replaced. You can use the public/ folder to have your index.php which will be copied to your output folder, or output the app to a separate folder and copy the files yourself.

This is by design and will not change. This is a build output folder, not a deploy folder. You should separate those two steps.

So, you can't really achieve what you exactly want, but this is the only workaround I found.

Comments

0

I found only one solution for me.

  1. create build for client side code by ng build --prod
  2. Using gulp copy generated files into Laravel public dir gulp copy (here you can check if old build files exists remove them)
  3. Using gulp-ingect plugin inject copied files into layout gulp inject

-- This can be used in CI and done with automation tools. In result we have inline.js and three *.**.bundle.js files injected. In same main layout i have statically add <base href="/example"> (you can use any defined in Laravel routes root path here) and inside template file which loaded from this path (in my case 'example.blade.php') add angular 2 root element <st-example>Loading...</st-example>

-- By this set up you have root Laravel layout which have inside required by angular 2 root url href and injected scripts files from build. And your template file for current route have root element inside (it included to main layout by simple blade yeild('content')).

P.S. also you must notice that if you are using some http requests in angular 2, after you integrate it into Laravel project this will add csrf protection middleware to each request... And if you have some new errors in requests which work previously just check headers.

Comments

0

Since angular-cli doesn’t allow you to specify index.php, let it be, simply specify index.html then there… And add an appropriate route into Laravel routing. Like this one, for instance:

Route::any('{path?}', function () {
    return File::get(public_path() . '/index.html');
})->where("path", ".+");

Btw, it’s simply a trap for any unknown routes… But I think you get an idea.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.