berthott/nglaravel

Build your angular frontend as part of your laravel project.

Maintainers

👁 berthott

Package info

github.com/berthott/nglaravel

pkg:composer/berthott/nglaravel

Statistics

Installs: 1 162

Dependents: 0

Suggesters: 0

Stars: 3

Open Issues: 0

3.0.0 2023-02-16 10:05 UTC

Requires

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 4359ee67b6a9e216e3a6fdb30aed55ec3718b130

  • Jan Bladt <berthott.woop@web.de>

This package is auto-updated.

Last update: 2026-06-11 17:48:44 UTC


README

👁 test workflow

NgLaravel

A helper for Angular + Laravel projects.

Easily use Laravel as your API backend and Angular with its CLI as frontend. Inspired by fristys' Blogpost.

Installation

You should set up your Laravel project first. Then require the package.

$ composer require berthott/nglaravel

Set up Angular

Choose a folder within or outside of your Laravel project to install your Angular project to. I recommend using the Angular CLI inside resources/angular.

In angular.json do the following changes:

"architect": {
 "build": {
 // ...
 "options": {
 "outputPath": "../../public/assets/angular",
 "deployUrl": "/assets/angular/",
 // ...
 },
 "configurations": {
 "production": {
 // ...
 "statsJson": true,
 // ...
 },
 "development": {
 "watch": true
 }
 }
 },
}

In the package.json of the angular project do the following changes:

"start": "ng build --configuration development --prod=false",
"build": "ng build",

By default default the package will look for Angulars output in public/assets/angular. If you choose to change the output path in angular.json please set the output property in config/angular.php or the NG_OUTPUT_PATH in .env accordingly.

How it works

The package will set up a generic web route that will catch anything apart from routes specified in the except_routes config, and forward it to a view including Angulars output scripts. In development these are the static files, in production a controller will read stats.json to include the correctly hashed files.

Options

To change the default options use

$ php artisan vendor:publish --provider="berthott\NgLaravel\NgBuildServiceProvider" --tag="config"
  • output: Determines Angulars path inside the public folder. Defaults to env('NG_OUTPUT_PATH', 'assets/angular').
  • except_routes: Determines the beginning of routes that should not be forwarded to angular. Defaults to ['api'].
  • middleware: Configurations for the route. Defaults to ['web'].

To change the default view use

$ php artisan vendor:publish --provider="berthott\NgLaravel\NgBuildServiceProvider" --tag="views"

Compatibility

Tested with Laravel 10.x and Angular 16.

License

See License File. Copyright © 2023 Jan Bladt.