- Notifications
You must be signed in to change notification settings - Fork7
A Babel plugin which automatically makes stack traces source-map aware
License
chocolateboy/babel-plugin-source-map-support
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
babel-plugin-source-map-support - a Babel plugin which automatically makes stack traces source-map aware
$ npm install source-map-support --save$ npm install babel-plugin-source-map-support --save-dev$ cat test.js
importfoofrom'foo';importbarfrom'bar';foo(bar);
$ babel --plugins source-map-support test.js
import'source-map-support/register';importfoofrom'foo';importbarfrom'bar';foo(bar);
This is aBabelplugin which prepends thefollowing statement to source files:
import'source-map-support/register';
In conjunction with thesource-map-support module,which must be installed separately, this statement hooks into the v8stack-trace API to translate call sites in the transpiled code back to theircorresponding 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-levelfile(s) of an application, but it no-ops if it has already been loaded, sothere's no harm in registering it in every file.
You probably don't want to use this plugin when compiling code for the webbecause you probably don't want to bundle source-maps and thesource-map-support module in minified code. An easy way to limit the plugin'sscope to development/test builds is to use Babel'senv option, e.g.:
{env:{development:{sourceMaps:'inline',plugins:['source-map-support', ...]}},presets:[ ...]}
Note that source-maps don't need to be inlined in each file. They can beexternalised by using the{ sourceMaps: true } option. This adds a link tothe bottom of each file which points to its generated source-map, e.g.:
{env:{development:{sourceMaps:true,plugins:['source-map-support', ...]}},}
// index.js footer://# sourceMappingURL=index.js.map
The following NPM scripts are available:
- build - compile the plugin and save it to the
distdirectory - build:doc - generate the README's TOC (table of contents)
- clean - remove the
distdirectory and other build artifacts - rebuild - clean the build artifacts and recompile the code
- test - rebuild the plugin and run the test suite
- test:debug - run the
testscript in debug mode, which dumps each transformed test case - test:prod - run the test suite in production mode
- test:run - run the test suite
- Babel >= 7
- Maintained Node.js versions
2.2.0
Copyright © 2015-2022 by chocolateboy.
This module is free software; you can redistribute it and/or modify it under theterms of theArtistic License 2.0.
About
A Babel plugin which automatically makes stack traces source-map aware
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.