Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
⌘K
Up or down tonavigateEnter toselectEscape toclose
On this page

deno compile, standalone executables

Command line usage:
deno compile [OPTIONS] [SCRIPT_ARG]...

Compiles the given script into a self contained executable.

deno compile --allow-read --allow-net jsr:@std/http/file-server
deno compile --output file_server jsr:@std/http/file-server

Any flags specified which affect runtime behavior will be applied to the resulting binary.

This allows distribution of a Deno application to systems that do not have Deno installed.Under the hood, it bundles a slimmed down version of the Deno runtime along with yourJavaScript or TypeScript code.

Cross-compiling to different target architectures is supported using the--target flag.On the first invocation ofdeno compile, Deno will download the relevant binary and cache it in$DENO_DIR.

Type checking optionsJump to heading

--checkJump to heading

Set type-checking behavior. This subcommand type-checks local modules by default, so adding --check is redundantIf the value of "all" is supplied, remote modules will be included.Alternatively, the 'deno check' subcommand can be used.

--no-checkJump to heading

Skip type-checking. If the value of "remote" is supplied, diagnostic errors from remote modules will be ignored.

Dependency management optionsJump to heading

--cached-onlyJump to heading

Require that remote dependencies are already cached.

--frozenJump to heading

Error out if lockfile is out of date.

--import-mapJump to heading

Load import map file from local file or remote URL.

--lockJump to heading

Check the specified lock file. (If value is not provided, defaults to "./deno.lock").

--no-lockJump to heading

Disable auto discovery of the lock file.

--no-npmJump to heading

Do not resolve npm modules.

--no-remoteJump to heading

Do not resolve remote modules.

--node-modules-dirJump to heading

Sets the node modules management mode for npm packages.

--reloadJump to heading

Short flag:-r

Reload source code cache (recompile TypeScript)no value Reload everythingjsr:@std/http/file-server,jsr:@std/assert/assert-equals Reloads specific modulesnpm: Reload all npm modulesnpm:chalk Reload specific npm module.

--vendorJump to heading

Toggles local vendor folder usage for remote modules and a node_modules folder for npm packages.

OptionsJump to heading

--allow-scriptsJump to heading

Allow running npm lifecycle scripts for the given packagesNote: Scripts will only be executed when using a node_modules directory (--node-modules-dir).

--certJump to heading

Load certificate authority from PEM encoded file.

--conditionsJump to heading

Use this argument to specify custom conditions for npm package exports. You can also use DENO_CONDITIONS env var..

--configJump to heading

Short flag:-c

Configure different aspects of deno including TypeScript, linting, and code formatting.Typically the configuration file will be calleddeno.json ordeno.jsonc andautomatically detected; in that case this flag is not necessary.

--env-fileJump to heading

Load environment variables from local fileOnly the first environment variable with a given key is used.Existing process environment variables are not overwritten, so if variables with the same names already exist in the environment, their values will be preserved.Where multiple declarations for the same environment variable exist in your .env file, the first one encountered is applied. This is determined by the order of the files you pass as arguments.

--extJump to heading

Set content type of the supplied file.

--locationJump to heading

Value of globalThis.location used by some web APIs.

--no-code-cacheJump to heading

Disable V8 code cache feature.

--no-configJump to heading

Disable automatic loading of the configuration file.

--permission-setJump to heading

Short flag:-P

--preloadJump to heading

A list of files that will be executed before the main module.

--seedJump to heading

Set the random number generator seed.

--v8-flagsJump to heading

To see a list of all available flags use --v8-flags=--helpFlags can also be set via the DENO_V8_FLAGS environment variable.Any flags set with this flag are appended after the DENO_V8_FLAGS environment variable.

Compile optionsJump to heading

--excludeJump to heading

Excludes a file/directory in the compiled executable.Use this flag to exclude a specific file or directory within the included files.For example, to exclude a certain folder in the bundled node_modules directory.

--iconJump to heading

Set the icon of the executable on Windows (.ico).

--includeJump to heading

Includes an additional module or file/directory in the compiled executable.Use this flag if a dynamically imported module or a web worker main modulefails to load in the executable or to embed a file or directory in the executable.This flag can be passed multiple times, to include multiple additional modules.

--no-terminalJump to heading

Hide terminal on Windows.

--outputJump to heading

Short flag:-o

Output file (defaults to $PWD/).

--targetJump to heading

Target OS architecture.

FlagsJump to heading

As withdeno install, the runtime flagsused to execute the script must be specified at compilation time. This includespermission flags.

deno compile --allow-read --allow-net jsr:@std/http/file-server

Script argumentscan be partially embedded.

deno compile --allow-read --allow-net jsr:@std/http/file-server -p 8080./file_server --help

Cross CompilationJump to heading

You can cross-compile binaries for other platforms by using the--target flag.

# Cross compile for Apple Silicondeno compile --target aarch64-apple-darwin main.ts# Cross compile for Windows with an icondeno compile --target x86_64-pc-windows-msvc --icon ./icon.ico main.ts

Supported TargetsJump to heading

Deno supports cross compiling to all targets regardless of the host platform.

OSArchitectureTarget
Windowsx86_64x86_64-pc-windows-msvc
macOSx86_64x86_64-apple-darwin
macOSARM64aarch64-apple-darwin
Linuxx86_64x86_64-unknown-linux-gnu
LinuxARM64aarch64-unknown-linux-gnu

IconsJump to heading

It is possible to add an icon to the executable by using the--icon flag whentargeting Windows. The icon must be in the.ico format.

deno compile --icon icon.ico main.ts# Cross compilation with icondeno compile --target x86_64-pc-windows-msvc --icon ./icon.ico main.ts

Dynamic ImportsJump to heading

By default, statically analyzable dynamic imports (imports that have the stringliteral within theimport("...") call expression) will be included in theoutput.

// calculator.ts and its dependencies will be included in the binaryconst calculator=awaitimport("./calculator.ts");

But non-statically analyzable dynamic imports won't:

const specifier= condition?"./calc.ts":"./better_calc.ts";const calculator=awaitimport(specifier);

To include non-statically analyzable dynamic imports, specify an--include <path> flag.

deno compile--include calc.ts--include better_calc.ts main.ts

Including Data Files or DirectoriesJump to heading

Starting in Deno 2.1, you can include files or directories in the executable byspecifying them via the--include <path> flag.

deno compile--include names.csv--include data main.ts

Then read the file relative to the directory path of the current module viaimport.meta.dirname:

// main.tsconst names= Deno.readTextFileSync(import.meta.dirname+"/names.csv");const dataFiles= Deno.readDirSync(import.meta.dirname+"/data");// use names and dataFiles here

Note this currently only works for files on the file system and not remotefiles.

WorkersJump to heading

Similarly to non-statically analyzable dynamic imports, code forworkers is not included in the compiledexecutable by default. There are two ways to include workers:

  1. Use the--include <path> flag to include the worker code.
deno compile--include worker.ts main.ts
  1. Import worker module using a statically analyzable import.
// main.tsimport"./worker.ts";
deno compile main.ts

Code SigningJump to heading

macOSJump to heading

By default, on macOS, the compiled executable will be signed using an ad-hocsignature which is the equivalent of runningcodesign -s -:

$ deno compile-o main main.ts$ codesign--verify-vv ./main./main: valid on disk./main: satisfies its Designated Requirement

You can specify a signing identity when code signing the executable just likeyou would do with any other macOS executable:

codesign-s"Developer ID Application: Your Name" ./main

Refer to theofficial documentationfor more information on codesigning and notarization on macOS.

WindowsJump to heading

On Windows, the compiled executable can be signed using theSignTool.exeutility.

$ deno compile-o main.exe main.ts$ signtool sign /fd SHA256 main.exe

Unavailable in executablesJump to heading

Did you find what you needed?

What can we do to improve this page?

If provided, you'll be @mentioned in the created GitHub issue

Privacy policy

[8]ページ先頭

©2009-2025 Movatter.jp