Skip to content
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

Pass sourcemap option to the compiler. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wontoncc
Copy link

@wontoncc wontoncc commented Dec 6, 2017

To enable generating sourcemap with rollup.

@adamhaile
Copy link
Owner

Sorry I missed this until now! I think adding sourcemap support for rollup is a great idea.

Looking at the code, I think there's a simpler change that would also be more powerful. Basically, I think I goofed when I wrote this initially, in that the options should be passed on to the compiler. So if we just replace the line:

		    return compiler.compile(code, { });

... with ...

		    return compiler.compile(code, options);

Then sourcemaps should work.

Thoughts?

@wontoncc
Copy link
Author

wontoncc commented Dec 17, 2017

This was my original thought at first, then I found that when sourcemap option is passed to the compiler, The return object does not contain the bundled output...
Not knowing whether its by design or not, I picked up this pattern. IMHO bundled output in the return object can be much better.

In addition, the rollup complains and fails to generate an output with sourcemap set to append and I dont really find out why due to the vague debugging message...

@adamhaile
Copy link
Owner

Ah, got it, I'm catching up.

Then how about something like:

    return compiler.compile(code, { sourcemap: options.sourcemap ? 'extract' : null });

BTW, I'm curious how the sourcemaps will work out with rollup. With webpack, they haven't been totally reliable, and I've never been able to figure out why not.

@wontoncc
Copy link
Author

I haven't encountered issues to generate sourcemap with rollup yet. It seems pretty reliable.

And yes, it can be done in the way you advise, involving some adjustment in the output from the compiler. I am going to open up a PR in surplus repo.

@adamhaile
Copy link
Owner

Hi Jason. I'd probably be more helpful if I actually pulled and built before throwing code change suggestions your way!

Main concern with the code as is is that it calls the compiler twice. This doubles build times, but also relies on deterministic output from the compiler. That's currently true for surplus but hasn't always been and may not be so in the future. Compilers often have to do things like generate random symbols which might change run-to-run.

What are the surplus changes you're thinking of?

@wontoncc
Copy link
Author

wontoncc commented Dec 19, 2017

Sorry! I just check the newest commit in the surplus repo and find that the compiler indeed returns compiled Javascript code. Just a little mismatch in the name of property, code is src: https://github.com/rollup/rollup/wiki/Plugins#conventions

Something like this should work (or similar modification on surplus/compiler):

var out = compiler.compile(code, options);
return {code: out.src || out, map: out.map || ''};

... and rollup will then complain about the graph in the comment in compiler/es/content.js#L219-L233 with sourcemap: 'extract'. Should be a problem of rollup in processing multiline comments though.

@Qix-
Copy link

Qix- commented Jan 4, 2019

beep boop any update on this? :)

With webpack, they haven't been totally reliable, and I've never been able to figure out why not.

Sourcemaps themselves are a poorly designed spec, IMO. This doesn't surprise me 😅 That's also why minification + source maps is still currently pretty much impossible.

At any rate, debugging Surplus in the browser right now is tricky due to poor sourcemap support. What changes need to be made in Surplus to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants