GithubHelp home page GithubHelp logo

chocolateboy / babel-plugin-source-map-support Goto Github PK

View Code? Open in Web Editor NEW
45.0 4.0 7.0 552 KB

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

License: Artistic License 2.0

JavaScript 100.00%
babel plugin source-maps source-map babel-plugin sourcemap sourcemaps node-package npm-package npm-module

babel-plugin-source-map-support's Introduction

Build Status NPM Version

NAME

babel-plugin-source-map-support - a Babel plugin which automatically makes stack traces source-map aware

INSTALL

$ npm install source-map-support --save
$ npm install babel-plugin-source-map-support --save-dev

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's 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 bundle source-maps and the source-map-support module in minified code. An easy way to limit the plugin's scope to development/test builds is to use Babel's env 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 be externalised by using the { sourceMaps: true } option. This adds a link to the 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

DEVELOPMENT

NPM Scripts

The following NPM scripts are available:

  • build - compile the plugin and save it to the dist directory
  • build:doc - generate the README's TOC (table of contents)
  • clean - remove the dist directory 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 test script in debug mode, which dumps each transformed test case
  • test:prod - run the test suite in production mode
  • test:run - run the test suite

COMPATIBILITY

SEE ALSO

VERSION

2.2.0

AUTHOR

chocolateboy

COPYRIGHT AND LICENSE

Copyright © 2015-2022 by chocolateboy.

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

babel-plugin-source-map-support's People

Contributors

chocolateboy avatar dependabot-support avatar mariodu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

babel-plugin-source-map-support's Issues

issue adding plugin to .babelrc

Hi there, trying to get your module working in attempt to fix some linenumber issues with mocha/babel.

getting the follow error:

Error: Cannot find module 'source-map-support/register'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)

have the following .babelrc file where the plugin is being used:

{
  "presets": ["es2015", "react", "stage-0"],
  "plugins": ["transform-object-rest-spread", "transform-decorators-legacy", "transform-class-properties"],
  "env": {
    "test": {
      "presets": ["es2015", "react", "stage-0"],
      "plugins": ["transform-object-rest-spread", "transform-decorators-legacy", "transform-class-properties", "rewire", "source-map-support"],
      "sourceMaps": "both"
    }
  }
}

and the test is run with babel-instanbul
"test:unit": "cross-env NODE_ENV=test babel-node node_modules/.bin/babel-istanbul cover --config=istanbul.json --dir coverage/unit node_modules/.bin/_mocha -- --require node_modules/ignore-styles 'client/**/*.spec.unit.js'",

its possible the error is coming from babel-istanbul as that tool is somewhat outdated.

Upgrade to Babel7

I know it is still in beta, but I would like to start testing this module with my app.

Doesn't work with Babel v6

I think I'm using this correctly, but please let me know if I'm not.

My commands:

webpack
babel --plugins source-map-support build/app.js

The result:

TypeError: Plugin is not a function
    at exports.default (src/plugin.js:28:12)
    at Function.memoisePluginContainer (/usr/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:127:13)
    at Function.normalisePlugin (/usr/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:161:32)
    at /usr/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:197:30
    at Array.map (native)
    at Function.normalisePlugins (/usr/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:173:20)
    at OptionManager.mergeOptions (/usr/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:271:36)
    at OptionManager.init (/usr/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/options/option-manager.js:416:10)
    at File.initOptions (/usr/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:190:75)
    at new File (/usr/lib/node_modules/babel-cli/node_modules/babel-core/lib/transformation/file/index.js:121:22)

Is this plugin broken in Babel 6?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.