44 stable releases
1.8.1 | Oct 2, 2024 |
---|---|
1.8.0 | Jul 1, 2024 |
1.7.0 | Jun 17, 2024 |
1.6.5 | Mar 7, 2024 |
1.3.1 | Nov 29, 2023 |
#590 in Command line utilities
24 downloads per month
70KB
1.5K
SLoC
bndl
Introducing bndl
, a barebones TypeScript transpiling and bundling tool for backend monorepos.
It aims to be a near drop-in replacement for those accustomed to tsc
, utilizing the existing tsconfig.json
in your project. bndl
traverses the monorepo, builds the current workspace with SWC, identifies the dependencies used by the consumer, and copies them to the compiled directory's node_modules
.
The result? An output directory containing everything necessary for your app to run. Simply copy the dist directory to a Docker image and execute it.
Installing
cargo
$ cargo install bndl_cli
npm
$ npm install -g bndl-cli
curl
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/segersniels/bndl/master/scripts/install.sh)"
wget
$ sh -c "$(wget https://raw.githubusercontent.com/segersniels/bndl/master/scripts/install.sh -O -)"
Usage
Usage: bndl [OPTIONS] [COMMAND]
Options:
-p, --project <project> The path to the project config file
--outDir <outDir> Specify an output folder for all emitted files.
--clean Clean the output folder if it exists before bundling
--only-bundle Skips compilation and only bundles the input files, assuming they are already compiled beforehand
--no-bundle Disable automatic bundling of internal monorepo dependencies
-m, --minify Minify the output bundle
-w, --watch Experimental: watch the input files for changes and recompile when they change
--exec <exec> Experimental: use in conjunction with --watch to execute a command after each successful compilation
-h, --help Print help
-V, --version Print version
Known limitations
Building dependencies
bndl
only builds the current workspace, not its dependencies. You need to build internal dependencies before the consuming workspace. Using something like Turborepo, you can run npx turbo run build --filter <your-workspace>
with a config like this:
{
"tasks": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**"]
}
}
}
This config ensures Turborepo builds internal dependencies first before the consuming workspace, making them ready for bundling.
Watch
bndl
only watches the current workspace for changes, not internal dependencies. To handle this, use the --exec
option to recompile and bundle internal dependencies.
bndl --watch --exec "npx turbo run build --filter <your-workspace>^... && npx bndl --only-bundle && npm run start"
This command will first build all internal dependencies (excluding the consuming application) and then tell bndl
to bundle them. Note that this triggers only when a file changes in the consuming application. Save a file in the consuming application to trigger a rebuild.
Using Turborepo and its cache should make this relatively fast, minimizing delay between file changes and restarts.
Contributing
Expect missing functionality and potential breakage. This tool was created for a specific use case and might differ from your needs. Feel free to open issues or PRs to add the functionality you need.
Submit issues with panic logs or debug information (RUST_LOG=debug bndl ...
) for quicker resolution.
Dependencies
~35–48MB
~850K SLoC