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.
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.jsonfile under thecommands.build.outDirproperty. - Type check and compile the code using
tsc. The tsconfig file path that will be used is defined inside the.athennarc.jsonfile under thecommands.build.tsconfigproperty. - Copy all the static files to the build folder. The
static files are registered inside the
.athennarc.jsonfile under thecommands.build.includearray. This property needs to always be used to copypackage.jsonandpackage-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:
- You must
cdinto the build folder and install production only dependencies:
cd build
npm ci --omit=dev
- You must always
cdinto the build folder and then run your app:
cd build
node bootstrap/main.js
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.