What Does Prepack Do?

You can learn the basics of what Prepack does and how it works from this overview.

It's not complete, but it can serve as a high-level overview while avoiding the computer science jargon.

Prepack CLI


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 ] [ -- | input.js ]


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 API

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


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


Prepack.prepackSources([{filePath, fileContents, sourceMapContents}], options) // returns { code: string, map: SourceMap }

File Async

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

File Sync

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


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.
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.
inlineExpressions boolean false Enables two passes in the serializer to improve code quality by avoiding intermediate variables.
logStatistics boolean false If true, logs statistics about the number of objects, functions and ids generated.
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.
timeout number Infinity Number of milliseconds to run a program before it times out. Useful to avoid infinite loops in the Prepacked program.