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

browserify with --source-maps? #208

Closed
ktodyruik opened this issue May 5, 2016 · 14 comments
Closed

browserify with --source-maps? #208

ktodyruik opened this issue May 5, 2016 · 14 comments

Comments

@ktodyruik
Copy link

Hi,

I'm new to purescript/pulp and trying it out.

I see that you can now do a pulp build with --source-maps.

pulp build --source-maps

That builds the node javascript.

Now, I'd like to build purescript to run in the browser.

pulp build --to main.js

That works but I don't seem to be able to use --source-maps with --to. How would you compile optimized purescript with sourcemaps to be run in a browser?

Thanks,
Kerry

@hdgarrood
Copy link
Collaborator

When you run pulp build with the --to argument, that runs psc to compile the code, and then psc-bundle, which concatenates everything into one file and performs dead code elimination. psc supports source maps right now, but unfortunately psc-bundle doesn't yet, so for now, you'll have to find some other bundler.

@nwolverson has very helpfully put together a summary of a few options: https://github.com/nwolverson/purescript-sourcemap-test (@nwolverson do you know if what is written there is still accurate?)

@nwolverson
Copy link
Collaborator

Yes, the bottom line is that psc-bundle doesn't support source maps, so --to will not support source maps. If you use a browserify (or webpack) without going via psc-bundle, this can work (as per the link above). So I'd suggest a non-optimised set up with source maps for a debug build, and going without for a release build.

I'm not likely to add source map support to psc-bundle any time soon unless it turns out to be surprisingly easy.

@hdgarrood
Copy link
Collaborator

Great, thanks. Do you think it's worth adding an issue to the compiler's issue tracker for source map support for psc-bundle, even so? There's a chance that someone else might pick it up, I guess?

@nwolverson
Copy link
Collaborator

Yes, that would make sense.

@hdgarrood
Copy link
Collaborator

Closing now that this is tracked at purescript/purescript#2096.

@tellnobody1
Copy link

@hdgarrood Starting from v0.10.4 psc-bunlde supports source-maps. I've tried pulp build --to main.js -- --source-maps but it gives me error:

psc-bundle: Source maps only supported when output file specified.

Looking at code I'm wondering why not to pass --to parameter to psc-bundle as --output?

@nwolverson
Copy link
Collaborator

@AndreyNe think it's more complicated than that, I was going to make changes for pulp but it seemed like there were rollup related changes happening. pulp needs to pass --source-maps to both psc and psc-bundle, which I think means it needs to be a real pulp option? I don't think options get passed to both. Then you need to use something like sorcery to combine source maps, which was in my mind to integrate with pulp

@paulyoung
Copy link

Have there been any changes regarding this?

@hdgarrood
Copy link
Collaborator

For there to be progress here someone needs to do some investigation to see how pulp would expose this functionality. It's not something I've needed so I'm unlikely to look at it myself any time soon, but if someone wants to investigate it I'd certainly consider changes to enable this.

@nwolverson
Copy link
Collaborator

I would add a --source-maps flag to the build and browserify commands, which passes --source-maps to purs build and purs bundle (if used), passes --debug to browserify in the latter case, and uses something like sorcery to glue these together (like this except I assume it has an API).

If that sounds reasonable I might eventually get to it but it won't be in the next few weeks (would be happy to be beaten to it).

@hdgarrood hdgarrood reopened this Jun 14, 2017
@hdgarrood
Copy link
Collaborator

That all sounds fine, except that I'm a bit apprehensive about using sorcery, as it self-describes as "a work-in-progress" and "suitable for playing around with". Are there other options in addition to sorcery?

@nwolverson
Copy link
Collaborator

To be fair it continues on to say "don't rely on it to debug air traffic control software or medical equipment" which I think sets the tone. I've had a quick search and don't see anything more mature (suggestions welcome, I saw https://github.com/jvilk/merge-source-maps https://github.com/thlorenz/combine-source-map https://www.npmjs.com/package/sourceify (browserify specific)), much seems to be integrated with grunt/gulp or more by way of taking input source maps to another transform to manipulate (eg uglify does this, I think webpack too).

In terms of map quality it would remain to be seen if issues stem from the additional transformations/combining maps or the original source maps - probably adding support to pulp would surface any issues as it gets easier to use.

@hdgarrood
Copy link
Collaborator

Ok, fair enough. I guess if a source map does come out slightly wrong it's not the end of the world anyway.

@damncabbage
Copy link
Contributor

I came across this issue for other pass-through options. I'm working on getting https://github.com/quicktype/quicktype to use the simple DCE that purs bundle provides, but changing the old invocation:

pulp build -- --source-maps --censor-warnings --stash

… to:

pulp build --to output/purs.js -- --source-maps --censor-warnings --stash

... has it whinge about these extra options, because the entire set is being given to both purs compile and purs bundle.

I tend to prefer strict pass-through (having Pulp be aware of every option and then passing them through) to prevent this sort of thing, but I understand that having it like this allows Pulp to support compiler changes / versions without chasing after each individual combination. I just don't really know an alternative, outside of --psa-options="--censor-warnings --stash" --bundle-options="--source-maps" or something.

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

No branches or pull requests

6 participants