A Babel plugin which automatically makes stack traces source-map aware
npm install babel-plugin-source-map-support
$ cat test.js
import foo from 'foo';
import bar from 'bar';
test();
$ babel --plugins source-map-support test.js
import 'source-map-support/register';
import foo from 'foo';
import bar from 'bar';
test();
This is a Babel plugin which prepends the following statement to source files:
import 'source-map-support/register';
In conjunction with the source-map-support module, which must be installed separately, this statement hooks into the v8 stack-trace API to translate call sites in the transpiled code back to their corresponding locations in the original code.
Note: this only works in environments which support the v8 stack-trace API (e.g. Node.js and Chrome), though it's harmless in other environments.
The source-map-support module only needs to be registered in the top-level file(s) of an application, but it no-ops if it has already been loaded, so there is no harm in registering it in every file.
Source maps must currently be inline. While the source-map-support module provides a way to associate a file with an external source map, that is not currently supported by this plugin.
The following NPM scripts are available:
- build - compile the plugin and save it to the target directory
- test - compile the plugin and run the test suite
- test:build - compile the plugin and run the test suite in debug mode (which dumps each transformed test case)
The following Gulp tasks are available:
- build - compile the plugin and save it to the target directory
- clean - remove the target directory and its contents
- default - alias for the
build
task
1.0.0
Copyright © 2015-2017 by chocolateboy
This module is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.