Skip to main content

Compilation

Understand the TypeScript compilation process of Athenna.

Introduction

One of the main objectives of the framework is to offer exceptional assistance for TypeScript. This extends beyond the benefits of static types and IntelliSense that enhance your coding experience. Furthermore, we make certain that there is no need for you to install extra build utilities for code compilation, both during the development phase and for production purposes.

warning

This documentation assumes that you have basic knowledge about TypeScript and the build tools available for it.

Compiling for development

If you are using artisan to run your application, it will already compile the code for you in run time, thanks to the ts-node/esm loader.

However, you may want to run a different TypeScript file using node.

For Node.js v20.x or higher:

node --import=@athenna/tsconfig index.ts

For Node.js v19.x or lower:

node --loader=ts-node/esm index.ts

Compiling for production

When you are ready to deploy your application to production, you can use the following command:

node artisan build

It performs the following operations:

  • Clean the existing build directory (if any). The build directory that will he cleaned is defined inside the .athennarc.json file under the commands.build.outDir property.
  • Type check and compile the code using tsc. The tsconfig file path that will be used is defined inside the .athennarc.json file under the commands.build.tsconfig property.
  • Copy all the static files to the build folder. The static files are registered inside the .athennarc.json file under the commands.build.include array. This property needs to always be used to copy package.json and package-lock.json.

Points to keep in mind

After building your code, the output folder becomes the root of your JavaScript application, this means two things:

  1. You must cd into the build folder and install production only dependencies:
cd build
npm ci --omit=dev
  1. You must always cd into the build folder and then run your app:
cd build
node bootstrap/main.js
warning

We do not copy the .env file to the output folder (even if you add it to commands.build.include array) to prevent issues for you. The environment variables are not transferable, you must define environment variables for production separately.