@@ -18,10 +18,13 @@ usage: qjs [options] [file [args]]
18
18
-m --module load as ES6 module (default=autodetect)
19
19
--script load as ES6 script (default=autodetect)
20
20
-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
22
22
-T --trace trace memory allocation
23
23
-d --dump dump the memory usage stats
24
24
-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
25
28
--memory-limit n limit the memory usage to 'n' Kbytes
26
29
--stack-size n limit the stack size to 'n' Kbytes
27
30
--unhandled-rejection dump unhandled promise rejections
@@ -52,6 +55,37 @@ DUMP_ATOMS 0x40000 /* dump atoms in JS_FreeRuntime */
52
55
DUMP_SHAPES 0x80000 /* dump shapes in JS_FreeRuntime */
53
56
```
54
57
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
+
55
89
## ` qjsc ` - The QuickJS JavaScript compiler
56
90
57
91
The ` qjsc ` executable runs the JavaScript compiler, it can generate bytecode from
0 commit comments