Creating Frontend Website Using Angular
Overview
- Create new SaaS project
- Edit
.devcontainer/Dockerfile
- Reopen the project in the Dev Container
- Delete frontend directory
- Generate new Angular frontend
- Build frontend
- Edit
config/development.yml
- Start Loco
Create new SaaS project
- Run
loco new
to create a new project - Navigate through the instructions until you reach the point where to decide what type of project to create
- Select "SaaS app (with DB and user auth)"
Edit ".devcontainer/Dockerfile"
- Open
.devcontainer/Dockerfile
- Replace the content with the following:
FROM mcr.microsoft.com/vscode/devcontainers/rust:0-1
# Install postgresql-client and sea-orm-cli
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends postgresql-client \
&& cargo install sea-orm-cli \
&& chown -R vscode /usr/local/cargo
# Install Node.js and npm
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - \
&& apt-get install -y nodejs
# Install Angular CLI
RUN npm install -g @angular/cli
COPY .env /.env
The Dockerfile will provide you with everything you need to develop a Loco app with an Angular frontend.
Reopen the project in the Dev Container
With VSCode it is super easy to reopen and run the project in a Dev Container.
- Press
Crtl + Shift + P
- Select
Dev Containers: Repopen in Container
- VSCode will open the project in the dev container. This can take a while when it is built for the first time.
- Delete the existing
frontend
directory
Loco comes with a Vite React frontend. We can delete the whole directory because the Angular CLI will set up everything we need
Generate new Angular frontend
- From the project root execute
ng new frontend
to create a new Angular project - Navigate through the instructions
Build frontend
- Run
ng build
to build the Angular frontend
Edit "config/development.yml"
As you may have noticed Angular has built the frontend into frontend/dist/frontend/browser
. We now need to configure Loco to access the built frontend from there.
-
Open
config/development.yml
-
Set the configs to the frontend build path:
a.
server.middlewares.static.folder.path: "frontend/dist/frontend/browser"
b.
server.middlewares.static.fallback: "frontend/dist/frontend/browser/index.html"
Start Loco
- Start Loco with
cargo loco start
- Open http://localhost:5150/
You should now see the Angular starter Website :smile: