2017-04-07 04:24:51 +03:00
# Prepack [![Circle CI](https://circleci.com/gh/facebook/prepack.png?style=shield&circle-token=1109197a81e634fd06e162c25d309a420585acd5)](https://circleci.com/gh/facebook/prepack)
2015-10-15 02:59:41 +03:00
2018-07-03 22:34:48 +03:00
< img src = "assets/PrepackLogo.png" width = 150 align = right >
2015-10-15 02:59:41 +03:00
Prepack is a partial evaluator for JavaScript. Prepack rewrites a JavaScript bundle, resulting in JavaScript code that executes more efficiently.
For initialization-heavy code, Prepack works best in an environment where JavaScript parsing is effectively cached.
2017-10-01 00:01:28 +03:00
See the official [prepack.io ](https://prepack.io ) website for an introduction and an [interactive REPL playground ](https://prepack.io/repl.html ).
2015-10-15 02:59:41 +03:00
2018-12-27 22:00:32 +03:00
## Status
**We, the Prepack team at Facebook, have temporarily set down work on Prepack including the React compiler project. You won't see many Prepack PRs while we are currently prioritizing some other projects. However, we'd like to resume work on Prepack again in a few months.**
2017-05-09 20:00:22 +03:00
## How to use Prepack
2017-07-11 03:30:45 +03:00
Install the CLI via npm,
2017-05-09 20:00:22 +03:00
```bash
2017-07-11 03:30:45 +03:00
$ npm install -g prepack
2017-05-09 20:00:22 +03:00
```
2017-07-11 03:30:45 +03:00
Or if you prefer yarn, make sure you get yarn first,
```bash
$ npm install -g yarn
```
and then install the Prepack CLI via yarn:
2017-05-09 20:00:22 +03:00
```bash
$ yarn global add prepack
```
2017-05-22 20:07:54 +03:00
You may need to `prepend` (pun intended!) the command with `sudo` in some cases.
2017-05-09 20:00:22 +03:00
### Let the party begin
To compile a file and print the output to the console:
```bash
$ prepack script.js
```
If you want to compile a file and output to another file:
```bash
$ prepack script.js --out script-processed.js
```
Detailed instructions and the API can be found at [Prepack CLI: Getting Started ](https://prepack.io/getting-started.html )
2017-12-08 05:19:17 +03:00
### Plugins to other tools
The following are a few plugins to other tools. They have been created and are maintained separately from Prepack itself. If you run into any issues with those plugins, please ask the plugin maintainers for support.
- [A Rollup plugin for Prepack ](https://www.npmjs.com/package/rollup-plugin-prepack )
- [A Webpack plugin for Prepack ](https://www.npmjs.com/package/prepack-webpack-plugin )
2018-06-02 22:37:53 +03:00
- [A Parcel plugin for Prepack ](https://www.npmjs.com/package/parcel-plugin-prepack )
2017-12-08 05:19:17 +03:00
- [A Visual Studio code plugin for Prepack ](https://marketplace.visualstudio.com/items?itemName=RobinMalfait.prepack-vscode )
- [A babel plugin which transforms Flow annotations into prepack model declarations ](https://www.npmjs.com/package/babel-plugin-flow-prepack ).
2018-12-27 22:00:32 +03:00
## Test Results and Code Coverage
2015-10-15 02:59:41 +03:00
2017-04-06 04:02:05 +03:00
- [test262 status on master branch ](https://circleci.com/api/v1/project/facebook/prepack/latest/artifacts/0/$CIRCLE_ARTIFACTS/test262-status.txt?branch=master )
2017-04-10 23:35:48 +03:00
- [code coverage report for serialization tests ](https://circleci.com/api/v1/project/facebook/prepack/latest/artifacts/0/$CIRCLE_ARTIFACTS/coverage-report-sourcemapped/index.html?branch=master )
2015-10-15 02:59:41 +03:00
- To see the status for a pull request, look for the message *All checks have passed* or *All checks have failed* . Click on *Show all checks* , *Details* , *Artifacts* , and then *test262-status.txt* or *coverage-report-sourcemapped/index.html* .
## How to get the code
0. Clone repository and make it your current directory.
1. `git submodule init`
2017-05-18 03:39:51 +03:00
2. `git submodule update --init`
2017-06-30 22:14:32 +03:00
3. Get yarn and node, then do
`yarn`
2015-10-15 02:59:41 +03:00
2017-07-11 03:30:45 +03:00
Note: For development work you really need `yarn` , as many scripts require it.
2015-10-15 02:59:41 +03:00
### How to build, lint, type check
0. Get the code
2017-06-30 22:14:32 +03:00
1. `yarn build`
You can later run `yarn watch` in the background to just compile changed files on the fly.
2. `yarn lint`
3. `yarn flow`
2015-10-15 02:59:41 +03:00
### How to run tests
0. Get the code
2017-06-30 22:14:32 +03:00
1. Make sure the code is built, either by running `yarn build` or `yarn watch`
2. `yarn test`
2015-10-15 02:59:41 +03:00
2017-05-22 20:07:54 +03:00
You can run individual test suites as follows:
2017-06-30 22:14:32 +03:00
- `yarn test-serializer`
2017-04-10 23:35:48 +03:00
This tests the interpreter and serializer. All tests should pass.
2017-06-30 22:14:32 +03:00
- `yarn test-test262`
2015-10-15 02:59:41 +03:00
This tests conformance against the test262 suite. Not all will pass, increasing conformance is work in progress.
## How to run the interpreter
0. Get the code
2017-06-30 22:14:32 +03:00
1. Make sure the code is built, either by running `yarn build` or `yarn watch`
2. `yarn repl`
2015-10-15 02:59:41 +03:00
This starts an interactive interpreter session.
## How to run Prepack
0. Get the code
2017-06-30 22:14:32 +03:00
1. Make sure the code is built, either by running `yarn build` or `yarn watch` .
2015-10-15 02:59:41 +03:00
2. Have a JavaScript file handy that you want to prepack, for example:
`echo "function hello() { return 'hello'; } function world() { return 'world'; } s = hello() + ' ' + world();" >/tmp/sample.js`
2018-03-30 02:34:59 +03:00
3. `cat /tmp/sample.js | yarn prepack-cli`
2015-10-15 02:59:41 +03:00
Try `--help` for more options.
## How to validate changes
Instead of building, linting, type checking, testing separately, the following does everything together:
2017-06-30 22:14:32 +03:00
`yarn validate`
2015-10-15 02:59:41 +03:00
2017-04-19 20:17:24 +03:00
## How to edit the website
2017-12-12 23:01:53 +03:00
The content for [prepack.io ](https://prepack.io ) resides in the [website directory ](https://github.com/facebook/prepack/tree/master/website ) of this repository. To make changes, submit a pull request, just like for any code changes.
2017-04-19 20:17:24 +03:00
2017-12-12 23:01:53 +03:00
In order to run the website locally at [localhost:8000 ](http://localhost:8000 ):
2018-07-03 21:50:39 +03:00
1. Build prepack into the website: `yarn build && mv prepack.min.js website/js`
2017-12-12 23:01:53 +03:00
2. Run `python -m SimpleHTTPServer` (Python 2) or `python -m http.server` (Python 3) from the `website/` directory
2017-04-19 20:17:24 +03:00
2015-10-15 02:59:41 +03:00
## How to contribute
2018-05-13 19:18:01 +03:00
To read more about the project, check out this [suggested reading wiki ](https://github.com/facebook/prepack/wiki/Suggested-reading )
2015-10-15 02:59:41 +03:00
For more information about contributing pull requests and issues, see our [Contribution Guidelines ](./CONTRIBUTING.md ).
## License
Prepack is BSD-licensed. We also provide an additional patent grant.