Prepack CLI

Installation

npm install -g prepack

Compiling a File

Compile a file and print it to the console:

prepack script.js

Compile a file and output to another file:

prepack script.js --out script-processed.js

If you want to output a source map file add the --srcmapOut. If your bundle was generated from some other compiler, Prepack will automatically look for a .map file but you can also specify it using the --srcmapIn option:

prepack script.js --out script-processed.js --srcmapIn script.map --srcmapOut script-processed.map

For advanced uses see the API options or prepack --help.

prepack [ --out output.js ] [ --compatibility jsc ] [ --mathRandomSeed seedvalue ] [ --srcmapIn inputMap ] [ --srcmapOut outputMap ] [ --speculate ] [ --trace ] [ -- | input.js ] [ --singlePass ] [ --debugNames ] [ --logStatistics ]

REPL

You can also run Prepack in REPL mode. This probably isn't very useful but it lets you test bugs in Prepack's interpreter.

prepack-repl

Prepack API

You can also use the programmatic API as a Node.js module.

Installation

npm install --save-dev prepack
var Prepack = require("prepack");
import { prepack, prepackFileSync } from 'prepack';
import * as Prepack from 'prepack';

String

Prepack.prepack(codeString, options) // returns { code: string, map: SourceMap }

Babel AST

Prepack.prepackFromAst(babelAstNode, code, options) // returns { code: string, map: SourceMap }

Note: Currently, the source code still has to be provided for Function.prototype.toString and error messages.

File Async

Prepack.prepackFile(filename, options, callback) // callback(error, { code: string, map: SourceMap })

File Sync

Prepack.prepackFileSync(filename, options) // returns { code: string, map: SourceMap }

Options

Option Type Default Description
filename string inferred Filename to use in error stacks.
inputSourceMapFilename string null If provided, this input source map file is used as the input before generating a new source map.
sourceMaps boolean false Determines whether a source map file should be generated.
compatibility "browser" | "jsc-600-1-4-17" "browser" Select a built-in environment compatibility. More built-in environments will be added in the future.
mathRandomSeed string null If a seed string is provided, Math.random() can be relied on and used in concrete code paths.
speculate boolean false Speculatively pre-execute more `require(...)` calls if they're part of the residual program.
trace boolean false Logs evaluated function calls.
debugNames boolean false If true, try to retain original variable and function names as part of the generated code.
singlePass boolean false Currently, the serializer makes two passes to optimize the variable naming in the output but this is slow so this lets you opt for a single pass. This option is expected to be unnecessary in the future.
logStatistics boolean false If true, logs statistics about the number of objects, functions and ids generated.
logModules boolean false If true, logs modules evaluated.
delayUnsupportedRequires boolean false If true, speculatively executed requires that failed to execute doesn't get preexecuted.
internalDebug boolean false If true, prints the JS stack inside of Prepack along with the stack in the Prepacked program. Useful for debugging Prepack itself.
uniqueSuffix string null If adds a unique suffix to generated IDs so that they don't risk colliding with anything else in the program. Expected to be automatic in the future.
timeout number Infinity Number of milliseconds to run a program before it times out. Useful to avoid infinite loops in the Prepacked program.
strictlyMonotonicDateNow boolean false Currently only used to run the Test262 test suite which requires reading Date.now() in increasing order.