-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Source maps #6
Comments
Plugins using one-to-one transforms could support source maps today by inlining them with data URLs. Here's an article with sample code at the bottom. |
@lluchs that's such a great idea! And that article is really helpful, thanks. So I wonder if it's be possible to, as a convention, always keep source maps inline, but then maybe have something like this for production: if ( gobble.env() === 'production' ) {
// find sourcemap comments, and create separate .map files
node = node.extractSourceMaps();
} Going to have to do some experimentin'. |
When you get there, this might come in handy: https://www.npmjs.org/package/exorcist |
Yeah, I have a tab open with that link! I was doing a load of research into sourcemaps over the weekend. I came to a realisation - none of this stuff matters if you can't solve the multi-level sourcemap problem (e.g. CoffeeScript -> JavaScript -> concatenated -> minified... even if each step emits a sourcemap, your devtools will only map back to the penultimate step), and sourcemaps are complicated enough that expecting people to start writing compilers that both ingest and generate sourcemaps is a total non-starter. So I started wondering if there's a simpler way. Here's what I came up with - sorcery.js. It's an early proof-of-concept but I think it has legs. The idea is that each transformation generates its own sourcemap (which can be inlined, using the technique in the article @lluchs mentions, or in a separate If it works (and early signs are encouraging), you'd be able to do this: node = gobble( 'src/coffee' )
.transform( 'coffee' )
.transform( 'concat' )
.transform( 'uglify' )
.transform( 'sorcery' ); The final step would (say) read The nice thing about this is that you don't need to complicate the API by allowing one-to-one transforms to also potentially be two-to-two - the most complex case is one-to-two, because no transformation needs to care about what came before it. So you could still do return compiledString; but maybe you could also do return {
code: compiledString,
map: sourceMap // gobble would need to fill in the `sources` property of the sourcemap
}; And the process of resolving sourcemap chains fails gracefully - if a file doesn't have a sourcemap, it's assumed to be an original source. |
As of 0.6.0, file transformers have experimental support for source maps, using the API described above - they can either return the code, or an object with a The Will sit with this for a bit longer and update docs etc if it all pans out. |
I was really interested in plumber because it transforms source maps as it processes the pipeline. If gobble can nail this then it'd be so great, plumber seems kinda buggy at the moment :( |
@nuisanceofcats Please do keep filing issues on Plumber repositories. We will get back to you! |
@nuisanceofcats I hear you. I'd love for sourcemaps to 'just work', and I think all the pieces are in place - it's just a matter of battle-testing, and ensuring that plugins can create sourcemaps. I've just updated the wiki to document the API for returning sourcemaps from file transformers. So I'll close this issue, but this is still a good place to discuss any sourcemap-related stuff until a new issue arises. FYI, the latest version of gobble-cli will attempt to use sourcemaps for debugging info. (The latest version of gobble needs to be installed locally for it to work.) The screenshot below has an example - some ES6 modules got concatenated with gobble-esperanto-bundle, which generated a sourcemap, but the subsequent transformation with gobble-es6-transpiler failed because es6-transpiler throws an error if it encounters a global variable it doesn't know about. On encountering the error, Gobble will:
There are a lot of moving parts, so it's all done very much on a 'best effort' basis, but when it works it makes life much easier. If anyone out there tries this out, I'd be very interested to hear how you get on. |
Going to open this issue before someone else does - one-to-one file transformers need to be able to support source maps somehow.
Not sure what that looks like, but it'd be a shame if plugin authors were to forgo the benefits of file transformers (i.e. using directory transformers instead, so they could read and write source maps) when doing file -> file-plus-sourcemap transforms (or file-plus-sourcemap -> file-plus-sourcemap).
The text was updated successfully, but these errors were encountered: