- node >= 4
- yarn >= 1.0.0 (with yarn workspaces support)
git clone https://github.com/babel/minify
cd minify
yarn
To build once:
yarn build
Or to do an incremental build in watch mode:
yarn watch
This project uses prettier for formatting code and eslint for other linting.
yarn lint
To fix formatting and other auto-fixable eslint errors,
yarn fix
To run all tests,
yarn test
To run tests for a specific package,
yarn test packages/babel-preset-minify
Prepare:
git submodule init
git submodule update
Run:
node smoke/run.js [options] [inputTests...]
Usage:
Usage: run [options] [inputTests...]
Options:
-h, --help output usage information
-i --skip-install Skip Install Step
-b --skip-build Skip Build step
-c --skip-cleanup Skip cleanup step
-q --quiet Quiet mode
Example:
To build and test lodash
,
node smoke/run.js lodash
To run smoke test without re-building and re-installing again
node smoke/run.js -ib lodash
benchmark.js compares BabelMinify with Uglify, Closure Compiler and Closure Compiler JS
./scripts/benchmark.js [file...]
plugin-timing.js is used to calculate and compare the time spent in each plugin.
./scripts/plugin-timing.js file.js
plugin-contribution.js calculates how much each plugin of babel-minify contributes to size reduction.
./scripts/plugin-contribution.js file.js
In your project, if you find that there is a bug that appears ONLY when you use BabelMinify, it's most likely that there is a bug in BabelMinify and you should definitely report it. Here are some guidelines that might help you drill down the issue. If it doesn't help you, you can of course create a minimal repro project with the bug and report it.
If you get a syntax error at compile time, then it could be a few things:
- The parser itself doesn't handle the syntax being used (a babylon bug).
- The code is actually invalid syntax.
- You didn't turn on the relevant Babel plugin for that syntax (if experimental).
If the syntax error occurs at runtime, it likely means the code generator (babel-generator) has a bug and has output invalid code.
When you run your minified code in the browser,
- If there is an error in the console, as a first step, look around the code block where the error happens, and the code block of a few steps up in the stack.
- Try to predict what caused the error and try relating it to some of the plugin names in the packages/ directory. The major ones (that do a lot of transformations) are - mangle, deadcode-elimination and simplify.
- Every plugin that Babel-Minify uses has an option in preset to toggle it on/off - preset-options
- Disable any transformation(s) that you suspect are causing problems. Turning OFF mangling (
mangle: false
) is a good practice if you don't think it's related to a mangling bug, since unmangled variable names will make debugging easier. - Sometimes it might NOT be a bug with one plugin but a combination of plugins. Again,
deadcode-elimination
andsimplify
maybe good candidates to start with here as they perform many transformations. - Sometimes it might because of the unsafe transformations. Some of them are grouped into a single option named
unsafe
. This option can help you identify it sooner if the bug is in one these plugins. - Produce a minimal repro of the same issue - the function block containing the bug should be enough to help reproduce the bug.
- Report it 🙂
- You're awesome. Thanks!
If you are releasing a new package, you'll want to run
./scripts/npm-owner-update.sh
to add all owners to the new npm package after releasing. Or do it manually viahttps://www.npmjs.com/package/package-name-here/access
.
If you need to update deps run npm run clean
and then npm run bootstrap
.
To get the changelog, run npm run changelog
to print to the terminal.
Use npm run publish
. It will run lerna publish
(we use --independent
) so it will prompt the version number for every package.