Creating an application from scratch with Aurelia
Tags: ts, aurelia, scratch
Published: 2021-06-17 20:22:47

---
title: Creating an application from scratch with Aurelia
published: true
description: Creating an application from scratch with Aurelia and Typescript
tags: ts, aurelia, scratch
cover_image: https://cdn-images-1.medium.com/max/800/1*ZM2PRtS86OcSXrKYGLTK3A.jpeg
---

I was introduced to Aurelia there by 2016, but at the time I did not give much importance, another javascript framework? I do not need this. A lot has changed since then, and my opinion has changed radically on this aspect of the javascript community. I currently love reading about new perspectives and ways of thinking and working with javascript.

First, let's the definitions, Aurelia is a Javascript framework for creating web applications, mobile, and desktop that takes advantage of simple conventions to empower your creativity. This is the quote from Aurelia's official website, but in fact, it's a collection of modules that will help you create any Javascript or Typescript application.

Aurelia was created by Rob Eisenberg who created the Durandal and Caliburn and has great similarities with the Angular 2, which is not surprising since Rob worked on the team that developed Angular 2.

But the big difference between the two is the philosophy of how the developer interacts as the framework. In Aurelia, the conventions are above the settings which leave the developer free to focus on the business rules.

So let's focus on the code that is what matters most to us, create a folder and boot your git repository and inside it install the dependencies we'll need, running.

{% gist https://gist.github.com/vidalvasconcelos/271af169fba31cf2ddd04a1f3fad17f5 %}

Now we have a ./node_modules with all of our dependencies, add it to your `.gitignore` just to not forget.

Our app will be a SPA, which means that the browser needs an index to hit and, load all files from application, so let’s create an index.html at the root of our application.

{%gist https://gist.github.com/vidalvasconcelos/a6ad625ae589478f9cc9014bcff1140f %}

Basically a standard HTML boilerplate, however, if you notice the <body> tag it contains an unusual property: aurelia-app="main". Yes, like other frameworks, Aurelia also has an entry point where will execute code so by placing this property Aurelia will inject its contents into the DOM and will invoke its start main module.

The main module invoke “boot” basically loads the default settings and switches on the debug mode that will spit the logs on the console.

{%gist https://gist.github.com/vidalvasconcelos/6b2b55b7299d8dc34d5c9c89e17bcc3f %}


This file may end up getting complex, but at first, we just need to set root our app.ts, which I prefer to keep in a specific folder called app, the only changes are the path that you pass as a string, but feel free.

My app.ts basically is a Typescript class, which has a unique string property called message.

{%gist https://gist.github.com/vidalvasconcelos/28d806ec981bf49178c159664f3b3ef2 %}

Remember the configurations conventions? Simple like this, this class already has bound with my template app.html.

{%gist https://gist.github.com/vidalvasconcelos/8348ff252eed5666e5191eaca74d3b02 %}

More before running our app exists a problem, we have not yet configured the Webpack to process our Typescript and Aurelia files. For this to work, let’s now create some necessary files like `tsconfig.json` and `webpack.config.js`, I will not go into detail about `tsconfig.json`, json it deserves a separate post on it.

{%gist https://gist.github.com/vidalvasconcelos/9aa1377f15b73394c95fbedd063f7ed2 %}

It basically informs the webpack which loaders will be responsible for processing each type of file and where we want it to spit out the processed files, which in our case will be the folder at the root of our project.

{%gist https://gist.github.com/vidalvasconcelos/5166e078b84c26f6585e309b8a3b0c30 %}


Now let’s run our app…


{%gist https://gist.github.com/vidalvasconcelos/4fd0f03198c91a3e6d372fdbc022184b %}

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qz84ipzk35j386ky8b2y.png)

You can check the complete code on my Github: [vidalvasconcelos](https://github.com/vidalvasconcelos/aurelia-minimal) and also the material on which I am based, such as the site [Aurelia](https://aurelia.io/home) and [Dwayne Charrington](https://ilikekillnerds.com/2017/03/creating-minimal-aurelia-typescript-webpack-application-scratch) articles.