@@ -18,10 +18,13 @@ usage: qjs [options] [file [args]]
1818-m --module load as ES6 module (default=autodetect)
1919 --script load as ES6 script (default=autodetect)
2020-I --include file include an additional file
21- --std make 'std' and 'os ' available to the loaded script
21+ --std make 'std', 'os' and 'bjson ' available to script
2222-T --trace trace memory allocation
2323-d --dump dump the memory usage stats
2424-D --dump-flags flags for dumping debug data (see DUMP_* defines)
25+ -c --compile FILE compile the given JS file as a standalone executable
26+ -o --out FILE output file for standalone executables
27+ --exe select the executable to use as the base, defaults to the current one
2528 --memory-limit n limit the memory usage to 'n' Kbytes
2629 --stack-size n limit the stack size to 'n' Kbytes
2730 --unhandled-rejection dump unhandled promise rejections
@@ -52,6 +55,37 @@ DUMP_ATOMS 0x40000 /* dump atoms in JS_FreeRuntime */
5255DUMP_SHAPES 0x80000 /* dump shapes in JS_FreeRuntime */
5356```
5457
58+ ### Creating standalone executables
59+
60+ With the ` qjs ` CLI it's possible to create standalone executables that will bundle the given JavaScript file
61+ alongside the binary.
62+
63+ ```
64+ $ qjs -c app.js -o app --exe qjs
65+ ```
66+
67+ The resulting ` app ` binary will have the same runtime dependencies as the ` qjs ` binary. This is acomplished
68+ by compiling the target JavaScript file to bytecode and adding it a copy of the executable, with a little
69+ trailer to help locate it.
70+
71+ Rather than using the current executable, it's possible to use the ` --exe ` switch to create standalone
72+ executables for other platforms.
73+
74+ No JavaScript bundling is performed, the specified JS file cannot depend on other files. A bundler such
75+ as ` esbuild ` can be used to generate an app bundle which can then be turned into the executable.
76+
77+ ```
78+ npx esbuild my-app/index.js \
79+ --bundle \
80+ --outfile=app.js \
81+ --external:qjs:* \
82+ --minify \
83+ --target=es2023 \
84+ --platform=neutral \
85+ --format=esm \
86+ --main-fields=main,module
87+ ```
88+
5589## ` qjsc ` - The QuickJS JavaScript compiler
5690
5791The ` qjsc ` executable runs the JavaScript compiler, it can generate bytecode from
0 commit comments