Skip to content

A Babel plugin which automatically makes stack traces source-map aware

License

Notifications You must be signed in to change notification settings

chocolateboy/babel-plugin-source-map-support

Repository files navigation

babel-plugin-source-map-support

npm status build status

A Babel plugin which automatically makes stack traces source-map aware

INSTALL

npm install babel-plugin-source-map-support

SYNOPSIS

$ cat test.js

import foo from 'foo';
import bar from 'bar';

foo(bar);

$ babel --plugins source-map-support test.js

import 'source-map-support/register';
import foo from 'foo';
import bar from 'bar';

foo(bar);

DESCRIPTION

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.

You probably don't want to use this plugin when compiling code for the web because you probably don't want to include inline source maps in minified code. An easy way to limit the plugin's use to development/test builds, is to use Babel's env option e.g.:

{
    env: {
        development: {
            sourceMaps: 'inline',
            plugins: ['source-map-support', ...]
        }
    },

    presets: [ ... ]
}

CAVEATS

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.

DEVELOPMENT

NPM Scripts

The following NPM scripts are available:

  • release - run the test script in production mode, which compiles the plugin for release
  • test - lint the codebase, compile the plugin, and run the test suite
  • test:debug - run the test script in debug mode, which dumps each transformed test case

Gulp Tasks

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 - run the clean, lint and build tasks
  • lint - check and report style and usage errors in the gulpfile, source file(s) and test file(s)

SEE ALSO

VERSION

2.0.0

AUTHOR

chocolateboy

COPYRIGHT AND LICENSE

Copyright © 2015-2018 by chocolateboy

This module is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.