Babel timing
Measure Babel compilation time file by file, plugin by plugin. See screenshot.
Note: this tool is in version 0, any minor release might introduce breaking changes.
Installation
Can be installed both as global or local dependency.
npm i babel-timing
yarn add babel-timing
Usage
CLI
babel-timing path/to/file-1.js path/to/file-2.js
babel-timing path/to/file-*.js
babel-timing path/to/entrypoint.js --follow-imports
Node
const babelTiming = require('babel-timing').babelTiming;
babelTiming(['path/to/file.js'], options);
Options
babelConfig
/ --babel-config
Type: string | false
Default: false
Path to a custom babel configuration file. By default Babel will try to load any existing valid configuration file.
followImports
/ --follow-imports
Type: bool
Default: false
Follow imported files/modules (using babel-collect-imports) and run babel-timing
against them.
Currently only relative paths are considered.
importPatterns
/ --import-patterns
Type: string[]
(cli accepts a string containing a comma-separated list)
Default: undefined
Include/exclude import paths according to the provided patterns.
output
/ --output
Type: string
Default: "return"
("console"
when called via CLI)
Options: "return"
, "console"
, "json"
Make babel-timing
results available as:
"return"
return results' object"console"
render results in console"json"
save results as babel-timing-results.json
How it works
Compile files with Babel 7 and get collect compilation info through wrapPluginVisitorMethod
Babel config option.
Optionally follow imports using babel-collect-imports.
Results
Compilation info are extracted into the following data structure:
type Results = {
name: string,
totalTime: number,
data: {
plugin: string,
timePerVisit: number,
time: number,
visits: number,
}[]
}[]
Notes
This tool started as an attempt of measuring the time taken by Babel while running transpiled tests or compiling applications with a bundler like Webpack.
I didn't find find a way of simply monitoring Babel while running the aforementioned tools, since I couldn't relate the wrapPluginVisitorMethod
calls to the file actually being compiled.
Any further idea/contribution to get to a better Babel monitoring solution is welcome.
Manual tests :)
node cli.js __fixtures__/file-1.js
node cli.js __fixtures__/file-1.js __fixtures__/file-2.js
node cli.js __fixtures__/*.js
node cli.js __fixtures__/entry.js --follow-imports
Thanks to
Todo
- Add
csv
output option - Expose
wrapPluginVisitorMethod
- Provide a way to consume
babel-timing
from other tools like webpack
, jest
, rollup
, etc.. - Unwrap and compile
node_modules
packages (absolute paths) - Prevent nested import discovery
- Find a more stable solution for making available pending
babel-collect-imports
Babel v7 update - Consider using a bundler instead of
babel-collect-import