İçeriğe geç
sern

Build

Bu içerik henüz dilinizde mevcut değil.

Terminal window
Usage: sern build [options]
Build your bot
Options:
-f --format [fmt] The module system of your application. `cjs` or `esm` (default: "esm")
-m --mode [mode] the mode for sern to build in. `production` or `development` (default: "development")
-W --suppress-warnings suppress experimental warning
-p --project [filePath] build with this sern.build file
-h, --help display help for command

Guiding Principles

When designing the sern build command, our aim was to make building bot applications as simple as possible for the majority of developers. The setup process has been streamlined, and most of the configuration details have been handled for you.

Here are some key points to keep in mind:

  1. Minimal Configuration: In the vast majority (99%) of use cases, developers do not need to configure the bot application building process. We believe that simplicity is key, so only a few decisions need to be made on the developer’s end.

  2. Optimal Defaults: We’ve chosen sensible defaults. This means you can get started without getting bogged down by complex, unneeded configurations.

  3. Finetuned for production bots: Our CLI leverages an opinionated build solution powered by esbuild. This ensures that bots are built without issues and can be shipped easily.

Experimental Features

Both the sern build and sern publish commands are marked as experimental. While they might not be completely stable, they are designed to work for the majority of users. We appreciate any feedback in helping us make these features even better.

Features

The sern build command comes equipped with a range of features designed to enhance your development process. Here’s a glimpse of what it offers:

  • esbuild Integration: our CLI takes inspiration from the efficiency of SvelteKit, ensuring your bot application is built effectively and with type safety. Leverage the esbuild plugin ecosystem.

  • Zero Configuration: Building your bot application without additional configuration. The CLI handles most of the setup for you.

  • Experimental Image Support: We’ve introduced experimental support for top-level imports of PNG and JPG files, making it easier to include images in your bot application.

  • Compile Time Constants: Customize your build with constants such as __DEV__, __PROD__, allowing you to tailor your application to different production stages.

  • Development and Production Modes: The CLI supports both development and production modes, enabling you to tailor your bot application for different stages of development.

  • Type-safe process.env: The CLI generates a type-safe process.env, reducing potential errors.

Implicits

  • Command line arguments take precendence over sern.build configuration file
  • Default build format is ESM
  • defineVersion = true
  • __DEV__ AND __PROD__ constants are configured.
  • Only a few tsconfig options are respected.

sern.build.js

The sern.build.js file is for any extra configuration you may need, such as adding esbuild plugins.

The CLI was intentionally made to be installed globally, and we can’t provide typings at a project level. If you need typings, here they are:

1
type BuildOptions = {
2
/**
3
* Define __VERSION__
4
* This option is a quick switch to defining the __VERSION__ constant which will be a string of the version provided in
5
* cwd's package.json
6
*/
7
defineVersion?: boolean;
8
/**
9
* default = esm
10
*/
11
format?: "cjs" | "esm";
12
/**
13
* extra esbuild plugins to build with sern.
14
*/
15
esbuildPlugins?: esbuild.Plugin[];
16
/**
17
* https://esbuild.github.io/api/#drop-labels
18
**/
19
dropLabels?: string[];
20
/**
21
* https://esbuild.github.io/api/#define
22
**/
23
define?: Record<string, string>;
24
/**
25
* Path to tsconfig
26
**/
27
tsconfig?: string;
28
/**
29
* default = 'development'
30
*/
31
mode: "production" | "development";
32
/**
33
* will search for env file. If none exists,
34
* default to .env.
35
*/
36
env?: string;
37
};

Usage

Terminal window
sern build

(that was easy)

Adapting Older Projects

Change your tsconfig.json to extend our generated one, ./.sern/tsconfig.json.

1
{
2
"extends": "./.sern/tsconfig.json",
3
"compilerOptions": {
4
// all of your old fields
5
}
6
}

In Depth

We use the define and drop labels API in C style macros to have easy development stage differences. Here is the esbuild full API documentation

Drop Labels

Terminal window
# mode is set to production
sern build
1
__DEV__: console.log("This is for production only");
2
__PROD__: console.log("This is for either mode");

Constants

sern builds with three default constants. __DEV__, __PROD__, __VERSION__, where __VERSION__ is the version in your build options, or package.json if unspecified.

Terminal window
sern build

Full esbuild documentation here. Add more to the define field in build options (only availible with a sern.build file at the moment)

process.env

We generate your process.env with dotenv and generate typings for process.env. Less hassle!

DISCORD_TOKEN=<your token>
1
process.env.DISCORD_TOKEN; // string | undefined (not typesafe :()