5

I am using Gulp with Browserify, and Babelify for ES6 and JSX-React transpiling. Despite numerous examples online, I can't figure out how to generate source-maps that point to the original pre-transpiled ES6/JSX files.

Here is my current gulp browserify task, which is based on this example:

gulp.task('browserify', function() {
  browserify({ entries: './src/js/main.jsx', extensions: ['.jsx'], debug: true })
    .transform(babelify, {presets: ["es2015", "react"]})
    .bundle()
    .pipe(source('main.js'))
    .pipe(buffer())
    .pipe(sourcemaps.init({loadMaps: true}))
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('dist/js'));
});

All this does is create a main.js.map file that seems to have the exact same content as the bundled main.js file. In Chrome it looks like this:

enter image description here

But I want to debug the original source .jsx and .js (with ES6 syntax) files. They look like this in my IDE:

enter image description here

How can I do this?

1
  • Like many before me, I switched to WebPack and got it working immediately. Commented Nov 28, 2015 at 22:49

2 Answers 2

2

Add sourcemaps:true to babelify options

{presets: ["es2015", "react"],sourcemaps:true}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I want to say I tried this and it made no difference, but I've since switched to WebPack which was much easier to get working, so unfortunately I can't verify this answer right now.
0

I simply had to change the settings in webpack.config.js

{ 
    devtool: 'source-map', // Or some other option that generates the original source as seen from https://webpack.github.io/docs/configuration.html#devtool
    ...
}

You don't have to modify the sourceMap query param in Babel Loader because it is inferred from the devtool option of the Webpack config.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.