@bytelab.studio/tsb
v3.1.0
Published
A simple, fast bundler system for TypeScript
Downloads
7
Maintainers
Readme
TSB
A simple, fast bundler system for TypeScript
Installation
npm install -g @bytelab.studio/tsb
Using 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 init
After 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.json
Step 2: Configure Your Project
A tsb.js
file is generated automatically and looks something like this:
tsb.js
is loaded in a sandbox context, so most Node.js features are disabled, includingrequire
modules, except fortsb
.
const {builder} = require("tsb");
builder
.module("my-module")
.addFolders("./src")
.output("./out")
.platform("nodejs")
- The
module
function sets the name of your project, similar to thename
property inpackage.json
. - The
addFolders
function adds a folder recursively to the source files. - The
output
function sets the output directory for your bundled files. - The
platform
function sets the output platform of the project, e.g.,nodejs
orbrowser
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 --script
Files are generated in the output folder:
out
├── chunks
│ └── <chunk>.js
└── <module>.js
Step 5: Run the Project
To run the project, use the following command:
node ./out/<module>.js
Now 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
- [x] Multi-platform support
- [x] Macro-Plugin
- [x] Enable loading chunks that are not directly integrated
- [x] Enable loading files via resource path