Bundling Apps (slice pack), Single-File Executables (slice compile) & Bytecode Inspection
When you deploy a Node.js, Deno, or Bun application to production, you typically have to ship hundreds of source files or a massive node_modules/ directory - and on every cold start, the runtime has to issue hundreds of OS stat(), open(), and read() syscalls just to locate your modules on disk.
Slice solves this with Zero-Stat Content-Addressed Storage (.cas) and Self-Contained Native Executables (SLICEEXE).
This chapter shows you how to structure multi-file TypeScript projects, bundle your code and node_modules/ with slice pack, embed frontend static assets (--static), compile everything into a single zero-dependency binary with slice compile, and inspect your bundles with slice inspect.
1. How Slice Resolves Your Project Structure Automatically
Section titled “1. How Slice Resolves Your Project Structure Automatically”You can pass a single .ts/.js file or an entire project directory to slice run, slice pack, slice compile, or slice serve.
When you pass a project directory (e.g., slice pack ./my-app ./my-app.cas), Slice resolves your entrypoint in the following priority order:
- Explicit
--entryCLI flag:slice pack ./my-app ./my-app.cas --entry=./src/worker.ts slice.toml[package] entrypoint: Readsentrypoint = "./src/index.ts"from./my-app/slice.toml.package.json: Reads"exports": { ".": "..." },"module", or"main".- Conventional Fallbacks: Checks
src/index.ts,src/index.tsx,index.ts,index.tsx,src/index.js,src/index.jsx,index.js,index.jsx,src/main.ts, andmain.ts.
Supported Module Formats & Imports
Section titled “Supported Module Formats & Imports”Inside your project, you can freely mix and match:
- TypeScript, TSX/JSX & ESM (
import/export):import { PricingEngine } from "./pricing_engine.ts"; // or "./pricing_engine" or "./pricing_engine.js"import type { OrderReceipt } from "./types.ts";import { renderToString } from "slice:jsx";import semver from "semver";import * as crypto from "node:crypto";export function ReceiptCard(props: { id: string; total: number }) {return <article className="receipt"><h2>Order {props.id}</h2><p>{props.total}</p></article>;} - CommonJS (
require/module.exports/exports):const ms = require("ms");const { parse } = require("fast-querystring"); - JSON & WebAssembly Files (
.json&.wasm):import config from "./config/default.json";import wasmBytes from "./kernel.wasm"; - Node, WinterTC & Slice Built-Ins:
- Core I/O, Streams, HTTP & Crypto:
"node:crypto","node:fs","node:fs/promises","node:stream","node:stream/promises","node:stream/web","node:http","node:https","node:http2","node:zlib","node:buffer","node:string_decoder" - Concurrency, Networking & Subprocesses:
"node:async_hooks","node:worker_threads","node:child_process","node:net","node:tls","node:dgram","node:dns","node:dns/promises","cloudflare:sockets","slice:sockets" - Paths, Diagnostics, CLI & Runtime:
"node:path","node:os","node:events","node:timers","node:timers/promises","node:url","node:querystring","node:util","node:util/types","node:assert","node:assert/strict","node:process","node:readline","node:readline/promises","node:perf_hooks","node:diagnostics_channel","node:tty","node:module","node:vm","node:v8","node:wasi","node:console","node:inspector","node:cluster" - Testing & JSX SSR:
"node:test","slice:test","bun:test","slice:jsx","react/jsx-runtime","preact/jsx-runtime","hono/jsx"
- Core I/O, Streams, HTTP & Crypto:
Modern ESM NPM Packages & Conditional "exports" Resolution
Section titled “Modern ESM NPM Packages & Conditional "exports" Resolution”Slice’s zero-stat bundler (crates/slice-cas/src/lib.rs) includes a full Oxc AST-driven ESM-to-CJS module linker (try_transform_esm_to_cjs_ast) and Node.js package.json "exports" resolver (resolve_package_exports_value):
- Conditional
"exports"Priority: Evaluates nested condition maps in edge-first priority order:"workerd"->"worker"->"edge-light"->"browser"->"import"->"require"->"node"->"default"(automatically skipping.d.tstype declarations). - Subpath & Wildcard
"exports": Resolves exact subpaths (such asimport { jwtVerify } from "jose/jwt/verify"orimport { createRouter } from "radix3") as well as wildcard patterns ("./*": "./dist/*.mjs"). - TypeScript
.js->.tsSpecifier Resolution: Supports standard TypeScript ESM imports written with.jsextensions (import { x } from "./foo.js"automatically resolves./foo.tswhen./foo.jsis not on disk). - Full ES2024+ & TypeScript Import/Export Lowering: Rewrites multi-line and whitespace-less
import{a,b as c}from"...", namespace imports (import * as ns), default + named imports, bare Node built-in specifiers (import fs from "fs"), TypeScriptimport x = require("...")andexport = ..., legacy/experimental@decoratorclasses/methods/parameters, Stage-3accessorfields, ES2026using/await using[Symbol.dispose]blocks, live-getter re-exports (export { x } from "./sub",export * from "./sub",export * as ns from "./sub"), and exported declarations (export class,export async function,export const { a, b } = ...) via Oxc AST span analysis without fragile regexes. - Unbundled Multi-Blob
.casExecution (CasBuilder::add_module/ingest_directory): In addition to bundled single-blob.casarchives produced byslice pack, Slice natively executes unbundled multi-blobMappedCasArchivearchives across both Tier-0 (SLICESNP\x02ImportCas) and Tier-1 (__slice_cas_requirebacked by stack-scopedActiveCasArchiveGuard) inslice run,slice serve,--tenant-dirhot-swap (open_detached), andSliceIsolate::execute_bytecodewith0hoststat()syscalls.
2. Packing a Zero-Stat .cas Archive (slice pack)
Section titled “2. Packing a Zero-Stat .cas Archive (slice pack)”slice pack compiles your TypeScript code using Oxc (v0.160.0), bundles all transitive local modules and node_modules/ dependencies, tree-shakes unused barrel submodules, hashes every artifact with BLAKE3-256, and writes a single 64-byte cache-line aligned .cas file.
2.1 Basic Usage
Section titled “2.1 Basic Usage”# Pack a single TypeScript fileslice pack ./src/index.ts ./bundle.cas
# Pack an entire folder project (with package.json, slice.toml, src/, and node_modules/)slice pack ./tests/apps/02-npm-ecosystem-suite ./npm-app.cas
# Pack with a custom entrypoint and embedded static frontend assetsslice pack ./my-webapp ./webapp.cas --entry=./src/server.ts --static=./public2.2 What Happens Inside slice pack (And Why It Makes Cold Starts So Fast)
Section titled “2.2 What Happens Inside slice pack (And Why It Makes Cold Starts So Fast)”- Oxc (
v0.160.0) Ahead-of-Time TypeScript Compilation & Comment Stripping:- All TypeScript types, interfaces, and JSDoc/license comments are stripped at build time.
- Dense Integer Module IDs (
0..N-1):- Instead of resolving string paths like
"./node_modules/semver/classes/semver.js"at runtime, Slice assigns every module a dense integer ID (0,1,2, …) so internalrequire()calls are O(1) array lookups.
- Instead of resolving string paths like
- Static Barrel Tree-Shaking (
50%+Smaller Bundles):- Many popular npm packages (like
semver) have anindex.jsbarrel file thatrequire()s 35+ submodules even if your app only callssemver.satisfies(). - Slice’s bundler statically analyzes which exports your application actually uses and prunes unused barrel submodules before reading them from disk, cutting
.casbundle size in half.
- Many popular npm packages (like
- Ahead-of-Time
SLICEBC\x01Precompiled BoaCodeBlockSerialization (Default):- By default (
boacas = true),slice packandslice compilecompile your bundled JavaScript into a 32-byteBoaCasHeader+SLICEBC1binaryCodeBlockcontainer (crates/slice-engine/src/vm/boacas.rs,vendor/boa_engine/SLICE_PATCH.md). - Inner functions inside
__slice_modules = [function(...) { ... }]are recorded via Oxc AST deferred source spans (0x11tag) so uncallednode_modulesfunctions are never byte-compiled until invoked, whilenode:*core built-ins and runtime shards are pre-fused into a singleCodeBlock. - At runtime,
slice run ./app.casreconstructsGc<CodeBlock>directly from themmapslice in microseconds - skipping 100% of runtime JavaScript lexing, AST parsing, scope analysis, and bytecode compilation.
- By default (
- Embedded
slice.tomlSecurity Manifest (manifest:/slice.toml):- If your project folder contains a
slice.tomlfile,slice packembeds it directly inside the.casarchive. When you runslice run ./app.casorslice serve ./app.cas, Slice automatically applies your[engine],[limits],[capabilities], and[server]settings!
- If your project folder contains a
- Memory-Mapped Execution (
0stat()Syscalls):- At runtime,
slice run ./app.casmaps the.casfile directly into virtual memory viammap(MAP_SHARED)and executes with zero filesystemstat()calls.
- At runtime,
3. Compiling Single-File Native Executables (slice compile)
Section titled “3. Compiling Single-File Native Executables (slice compile)”Want to distribute a CLI tool, microservice, or edge worker to servers or customers without installing slice, node, or any source files on the target machine?
Use slice compile to fuse the native slice runtime binary and your .cas bundle into a single, zero-dependency executable (SLICEEXE):
# Compile a folder app (including node_modules/ and slice.toml) into a standalone executableslice compile ./tests/apps/01-fintech-checkout -o ./fintech-checkout
# Or compile a full-stack web app (Backend API + ./public Frontend UI) into one binaryslice compile ./my-webapp -o ./my-webapp-bin --static=./publicRunning Your Compiled Binary
Section titled “Running Your Compiled Binary”The generated binary (./fintech-checkout on Linux/macOS, .\fintech-checkout.exe on Windows) runs directly, honors any embedded slice.toml manifest, accepts runtime flags (--warm, --metrics, --quiet, --allow-*, --fuel, --memory), and forwards remaining CLI arguments into process.argv:
./fintech-checkout --warm --metricsOutput:
{"app":"01-fintech-checkout","ordersProcessed":50,"approvedCount":50,"aggregateRevenueCents":4932364,"lastSha256Signature":"636588368661f40b"}[Slice Standalone] Tier: Tier1Baseline | Instantiate: 0.08 us | Exec: 673.00 us | Total: 673.08 us | Memory: 4096 B | Stat Syscalls: 0How
SLICEEXEWorks Without Temp-File Extraction: Unlike Nodeseaorpkgtools that unpack megabytes of files into/tmpon startup, aSLICEEXEbinary memory-maps its own executable file at the exact 64-byte aligned offset where the embedded.casarchive begins. Cold start takes microseconds and writes 0 bytes to/tmp.
4. Inspecting Bundles, Offsets & Bytecode (slice inspect)
Section titled “4. Inspecting Bundles, Offsets & Bytecode (slice inspect)”Use slice inspect whenever you want to verify what modules were bundled into a .cas archive, check 64-byte cache-line alignment, or see the exact SLICESNP / SLICEBOA bytecode generated for a .ts script.
4.1 Inspecting a .cas Archive
Section titled “4.1 Inspecting a .cas Archive”slice pack ./tests/apps/01-fintech-checkout ./fintech.casslice inspect ./fintech.casExample output:
========================================================================= SLICE ZERO-STAT CAS ARCHIVE INSPECTOR: ./fintech.cas========================================================================= CAS Format Version : v1 Total Mapped Size : 8192 bytes Entrypoint Hash : 4a8e9c1b7d3f2056... Static Web Assets : 0 embedded files Modules Indexed : 1------------------------------------------------------------------------- [000] Specifier : ./tests/apps/01-fintech-checkout BLAKE3 : 4a8e9c1b7d3f2056... Source : offset=448 (64B aligned=true), len=3412 bytes Bytecode : offset=3904 (64B aligned=true), len=3420 bytes=========================================================================4.2 Inspecting a TypeScript Script’s Bytecode
Section titled “4.2 Inspecting a TypeScript Script’s Bytecode”slice inspect ./src/index.ts- For Tier-1 Default (
SLICEBC\x01) bundles,slice inspectprints the precompiledBOACAS_PRECOMPheader summary (Approach=1, feature flags, precomputed runtime shard mask,SLICEBC1CodeBlockbyte size, and deferred module fallback source size). - For Tier-0 / Tier-2 (
SLICESNP) scripts,slice inspectprints the disassembled instruction table (CONST_NUM,CONST_STR,MONO_FOR_T2,AST_EXEC,EXPORT_SYM). - For Legacy Source-in-CAS (
SLICEBOA,--no-boacas) bundles,slice inspectprints the bundled JavaScript payload,// #slice-source:error-mapping markers, and the//__SLICE_RC:<hash>persistent realm cache key.
5. Source-Line Error Mapping in Multi-File Bundles
Section titled “5. Source-Line Error Mapping in Multi-File Bundles”When slice-cas bundles multiple TypeScript files from src/ into a single .cas archive, it automatically inserts lightweight // #slice-source: <short_path>|<full_path> markers before each user module.
If an uncaught error is thrown inside one of your bundled TypeScript modules at runtime, Slice’s error mapper (slice_cas::map_bundled_error_location) automatically translates the bundled line number back to your original TypeScript file and line number (e.g., src/pricing_engine.ts:42), so you never have to hunt through a concatenated bundle to debug an exception.