ben-ng/minifyify

does not support input source map

boblauer opened this issue · 10 comments

I'm bundling several React jsx files using babelify. Babelify will output a source map that correctly points back to the jsx files. However, once I run the bundle through minifyify, the source map points back to the converted javascript, not the original javascript.

I imagine this would be a similar issue if someone were using coffeescript. The minifyify source map would show the converted javascript, rather than the original coffeescript.

How is babelify outputting this source map? When I got this feature working with coffeescript, the source map was embedded in the output for each file, with sourcesContent and all.

babelify embeds the source map as a base64 string at the bottom of the file. ex:

//# sourceMappingURL=data:application/json;base64,{base64string}

Looking at the decoded json object, it has the following keys:

'version', 'sources', 'names', 'mappings', 'file', 'sourceRoot', 'sourcesContent'

My apologies, I was accidentally bundling the javascript twice. Everything works great. Thanks for the awesome package, so much easier than the alternatives!

Thanks for the update, I was scratching my head on this one!

How did you set this up? I'm having a similar issue with browserify + babelify + minifyify

I'm combining them like this to try to have a minimal working thing before adding more options:

browserify --entry src\app\init.js --debug --extension=jsx --transform [ babelify --stage 1 ] --plugin [minifyify --map app.js.map --output build/app.js.map] --outfile build/app.js

However, when I look at it in Chrome, I get the babelified sources instead of the original js files.

Can you verify that, before minifyify is added into the mix, the babelify plugin is adding inline source maps to each file? I use minifyify and babelify too, but programmatically, and its been working great.

Yes, the bundle had inline source maps. I used it programmatically first, but it didn't work, so I tried cmdline with the same result.

I switched to gulp-sourcemaps yesterday, which worked, so for me the end result is fine ;)

@ben-ng Could you be so kind as to provide your code?

My problematic code looks like the following. Firefox tells me I am assigning two sourcemap files to the same bundle. How?

  browserify({ debug: true })
    .transform(babelify)
    .require(input, { entry: true })
    .plugin('minifyify', { map: 'static/bundle.js.map', output: 'static/bundle.js.map' })
    .bundle()
    .on('error', function (err) { log("Error: " + err.message) })
    .pipe(fs.createWriteStream(output))

@pguth i think the only thing i'm doing differently is using the callback in bundle() instead of using streaming + the output option.

Sadly, source-maps are generated but not referenced.

$ browserify demo/main.js -d -t [ babelify ] -p [ minifyify --output demo/bundle.js.map ] -o demo/bundle.js