Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs about compilation #94

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 93 additions & 1 deletion docs/the-basics/compilation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,96 @@ Understand the TypeScript compilation process of Athenna.

## Introduction

Coming soon
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 a basic knowledge
about TypeScript and the build tools available for it.

:::

## Compiling for development

In the root path of your project you already have a
shell script file called `node`, This file is useful
for development purposes because it allows you to run
TypeScript files without having to add the
`--loader=ts-node/esm` option every time:

```shell
./node index.ts
```

This file works exactly like the `node` command, you
can set all node flags before the path to the file you
want to execute:

```shell
./node --watch index.ts
```

:::tip

You can learn more about the `node` file in the
[node script file documentation section](/docs/getting-started/node-sript-file).

:::

## Compiling for production

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

```shell
./node artisan build
```

It performs the following operations:

- Clean the existing build directory (if any).
- 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.metaFiles` 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:

```shell
cd build
npm ci --omit=dev
```

2. You must always `cd` into the build folder and then
run your app:

```shell
cd build
node --experimental-import-meta-resolve bootstrap/main.js
```

:::warning

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

:::
Loading