Skip to content

Commit d50571b

Browse files
committed
fixup: docs!
1 parent 7b607eb commit d50571b

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

docs/docs/cli.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 */
5255
DUMP_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

5791
The `qjsc` executable runs the JavaScript compiler, it can generate bytecode from

qjs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,9 @@ void help(void)
387387
"-T --trace trace memory allocation\n"
388388
"-d --dump dump the memory usage stats\n"
389389
"-D --dump-flags flags for dumping debug data (see DUMP_* defines)\n"
390-
"-c --compile FILE compile the given JS file as a standalone executable\n"
391-
"-o --out FILE output file for standalone executables\n"
392-
"--exe select the executable to use as the base, defaults to the current one\n"
390+
"-c --compile FILE compile the given JS file as a standalone executable\n"
391+
"-o --out FILE output file for standalone executables\n"
392+
" --exe select the executable to use as the base, defaults to the current one\n"
393393
" --memory-limit n limit the memory usage to 'n' Kbytes\n"
394394
" --stack-size n limit the stack size to 'n' Kbytes\n"
395395
" --unhandled-rejection dump unhandled promise rejections\n"

0 commit comments

Comments
 (0)