Skip to content

These docs are for Miniflare 2 which is no longer supported apart from critical security updates.
Please see the migration guide to upgrade to Miniflare 3, and the updated API docs.

Miniflare
Visit Miniflare on GitHub
Set theme to dark (โ‡ง+D)

๐Ÿ›  Builds

Custom Builds

Custom builds can be enabled by specifying a build command. You can also specify a path to run the build in, and a path to watch:

$ miniflare --build-command "npm run build" # or -B
$ miniflare --build-command "npm run build" --build-base-path "build"
$ miniflare --build-command "npm run build" --build-watch-path "source1" --build-watch-path "source2"
wrangler.toml
[build]
command = "npm run build"
# Below options are optional
cwd = "build"
watch_dir = "source" # Defaults to "src" if command set
# Extra build watch paths can be specified here,
# they'll get merged with `watch_dir`
[miniflare]
build_watch_dirs = ["source1", "source2"]
const mf = new Miniflare({
buildCommand: "npm run build",
// Below options are optional
buildBasePath: "build",
buildWatchPaths: ["source1", "source2"], // Defaults to "src" if command set
});

The build command will be executed once on initial worker load, then again every time something in the watched page changes. Note that scripts will only be reloaded when scriptPath's contents changes, so make sure that's set to your build output. You can either pass this explicitly, or set it in wrangler.toml:

[build.upload]
dir = "" # Defaults to "dist"
main = "./output.js"

Wrangler Builds

Miniflare supports building webpack and rust type Wrangler projects too. This is done internally by automatically setting a default custom build configuration which calls wrangler build to do the actual building.

Webpack

wrangler.toml
type = "webpack"

Requires Wrangler 1 to be installed.

Rust

wrangler.toml
type = "rust"

Requires Wrangler 1 and Rust to be installed.