chore: use alternative ways to bundle

This commit is contained in:
PalmDevs
2024-07-04 21:02:01 +07:00
parent ebf1ac7c08
commit 9b6ba56d99
50 changed files with 443 additions and 399 deletions

View File

@@ -42,4 +42,4 @@ The possible levels (sorted by their importance descendingly) are:
The next page will tell you how to run and bundle the server.
Continue: [🏃🏻‍♂️ Running the server](./2_running.md)
Continue: [🏃🏻‍♂️ Running the server](./2_running_and_deploying.md)

View File

@@ -1,54 +0,0 @@
# 🏃🏻‍♂️ Running the server
There are many methods to run the server. Choose one that suits best for the situation.
## 👷🏻 Development mode (recommended)
There will be no compilation step, and Bun will automatically watch changes and restart the server for you.
You can quickly start the server by running:
```sh
bun dev
```
## 🌐 Production mode
Production mode runs no different from the development server, it simply has less debugging information printed to console by default. However, more production-specific features may come.
To start the server in production mode, you'll have to:
1. Set the `NODE_ENV` environment variable to `production`
> It is very possible to set the value in the `.env` file and let Bun load it, **but it is recommended to set the variable before Bun even starts**.
2. Start the server
```sh
bun dev
```
## 📦 Building
If you're looking to build and host the server somewhere else, you can run:
```sh
bun bundle
```
The files will be placed in the `dist` directory. **Configurations and `.env` files will NOT be copied automatically.**
To start up the server, you'll need to install `tesseract.js` first.
```sh
bun install tesseract.js
# or
bun install tesseract.js -g
# Run the server
bun run index.js
```
## ⏭️ What's next
The next page will tell you about packets.
Continue: [📨 Packets](./3_packets.md)

View File

@@ -0,0 +1,59 @@
# 🏃🏻‍♂️ Running and deploying the server
There are many methods to run the server. Choose one that suits best for the situation.
## 👷🏻 Development mode
There will be no compilation step, and Bun will automatically watch changes and restart the server for you.
You can quickly start the server by running:
```sh
bun dev
```
## 📦 Building
If you're looking to build and host the server somewhere else, you can run:
```sh
bun run build
```
The distribution files will be placed inside the `dist` directory. Inside will include:
- The default configuration for the API
- Compiled source files of the API
You'll need to also copy the `node_modules` directory dereferenced if you want to run the distribution files somewhere else.
## ✈️ Deploying
To deploy the API, you'll need to:
1. [Build the API as seen in the previous step](#-building)
2. Copy contents of the `dist` directory
```sh
# For instance, we'll copy them both to /usr/src/api
cp -R ./dist/* /usr/src/api
```
3. Replace the default configuration *(optional)*
4. Configure environment variables
As seen in [`.env.example`](../.env.example). You can also optionally use a `.env` file which **Bun will automatically load**.
5. Finally, you can run the API using these commands
```sh
cd /usr/src/api
bun run index.js
```
## ⏭️ What's next
The next page will tell you about packets.
Continue: [📨 Packets](./3_packets.md)