@bytelab.studio/tsb v3.1.0
TSB
A simple, fast bundler system for TypeScript
Installation
npm install -g @bytelab.studio/tsbUsing the tool
To use the tsb tool for your project, follow the steps below.
Step 1: Initialize a Project
First, let tsb handle the setup
tsb initAfter running the command, your file structure should look like this:
.
├── node_modules
│ └── @bytelab.studio
│ └── tsb-runtime
├── out
├── package-lock.json
├── package.json
├── src
├── tsb.js
└── tsconfig.jsonStep 2: Configure Your Project
A tsb.js file is generated automatically and looks something like this:
tsb.jsis loaded in a sandbox context, so most Node.js features are disabled, includingrequiremodules, except fortsb.
const {builder} = require("tsb");
builder
.module("my-module")
.addFolders("./src")
.output("./out")
.platform("nodejs")- The
modulefunction sets the name of your project, similar to thenameproperty inpackage.json. - The
addFoldersfunction adds a folder recursively to the source files. - The
outputfunction sets the output directory for your bundled files. - The
platformfunction sets the output platform of the project, e.g.,nodejsorbrowser
All flags except --script and -h | --help can be set through the config file.
Usage: tsb build <files> [options]
-m=name, --module=name The module name
<> The files to be compiled
-p=platform, --platform=platform
The target platform
-e=file, --entry=file The entry file
-o=path, --output=path The output path
--chunk-size=bytes Sets the minimal chunk size in bytes
--script Use tsb.js definition in the CWD
-h, --help Prints this help string
--plugin-minify Minifies the JavaScript output| Flag | Function |
|---|---|
| <files> | addFiles, addFolders |
| -m, --module | module |
| -p, --platform | platform |
| -e, --entry | entry |
| --chunk-size | chunkSize |
| --plugin-* | plugins |
Step 3: Write Program Content
Now, write the actual program.
// src/foo.ts
export function foo() {
console.log("Foo");
}// src/entry.ts
import {foo} from "./foo"
foo();Step 4: Build the Project
To build the project, run the following command in your project directory:
tsb build --scriptFiles are generated in the output folder:
out
├── chunks
│ └── <chunk>.js
└── <module>.jsStep 5: Run the Project
To run the project, use the following command:
node ./out/<module>.jsNow your project is set up, configured, and ready to run using tsb.
NodeJS Modules
Currently, there is no way to include NodeJS modules directly in the bundled files. However, loading of NodeJS modules is supported on the NodeJS platform, and context switching with AppDomains across NodeJS modules is also supported.
Roadmap
Nothing in this roadmap is a promise. Everything in this roadmap is changeable.
Planned
- Some sort of library system using NPM to install bundled libraries
v3.1.0
- Multi-platform support
- Macro-Plugin
- Enable loading chunks that are not directly integrated
- Enable loading files via resource path