@ryanke/violet
v0.0.2
Published
> [!IMPORTANT] > This is absolutely not ready for production - a lot of features are missing, incomplete, or untested.
Downloads
3
Readme
violet
[!IMPORTANT] This is absolutely not ready for production - a lot of features are missing, incomplete, or untested.
Bundle your TypeScript app or library with ease.
- Reduce the size of Docker builds
- Support macros for compile-time code generation
- Make sure you forget you're using ESM
- Handle bundling optional dependencies properly
installation
# only pnpm is supported for now. violet needs to read the lockfile
pnpm add @ryanke/violet
For improved compatibility, you may also update your tsconfig.json
to extend the included preset, it may fix some issues that either slow down or break bundling in some circumstances.
{
"extends": "@ryanke/violet/tsconfig-base.json",
// or...
"extends": ["...", "@ryanke/violet/tsconfig-base.json"]
}
Then, to run and build your app, you can add this to your package.json
{
"scripts": {
"build": "tsc --noEmit && violet build ./src/index.ts",
"dev": "violet run --watch ./src/index.ts",
"start": "node ./dist/index.js"
}
}
usage
# run an app, similar to `tsx` or `ts-node`
# this builds your app in the background and runs it on success
violet run ./src/index.ts --args-to-pass
violet run --watch ./src/main.ts
# build your app
# automatically bundles app dependencies except those in package.json "dependencies"
# "devDependencies" are always bundled - if you want to bundle everything, move everything to "devDependencies"
violet build ./src/index.ts
# there are a few additional options, run `violet --help` for more info
macros
[!IMPORTANT] Because of unfortunate limitations with esbuild and swc, macros do not work in files that require decorator metadata. This may be fixed in the future.
Macros are functions that run at compile time. Unlike rust, you cannot generate code with macros (yet..!), but they can still be extremely powerful in the right circumstances.
// helpers.ts
import { execSync } from "child_process";
export const getCommitHash = async () => {
return execSync("git rev-parse HEAD").toString().trim();
};
// index.ts
import { getCommitHash } from "./helpers.js" assert { type: "macro" };
const commitHash = await getCommitHash();
This will compile to:
const commitHash = "7fe6d2c105dec483c85355976d6f4307c78e66bc";