Build a library of modules in PureScript

174 views
Skip to first unread message

rvdalen

unread,
Sep 25, 2017, 11:07:33 AM9/25/17
to purescript
Hi everyone,

I want to use PureScript to build a library that I can call from normal JavaScript.
I am not sure how to do this?

The command I normally use to generate JS is:  `pulp build --to dist/resources/app/output.js`, but this eliminates any
other modules I have defined, but have not used (because of dead code elimination).

I do not need or care about a Main module.  I just want to define a bunch of my own modules
in PureScript and have those (and their dependencies) available in the browser.

How can I get pulp to generate such output?

Regards
--Rouan

Phil Freeman

unread,
Sep 25, 2017, 2:14:32 PM9/25/17
to purescript
Hi Rouan,

You can do this using pulp build without the --to option. You'll get a bunch of common js modules in the output directory.

Thanks,

Phil.

--
You received this message because you are subscribed to the Google Groups "purescript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to purescript+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/purescript.
For more options, visit https://groups.google.com/d/optout.

rvdalen

unread,
Sep 26, 2017, 2:09:41 AM9/26/17
to purescript

 Hi Phil,

Thanks, will this remove any unused modules that I do not refer to in my
own modules?  I still want the dead code elimination for things I do not use in
any of my modules.

Regards
--Rouan
 

rvdalen

unread,
Sep 26, 2017, 2:23:20 AM9/26/17
to purescript
Hi Phil,

I still want all the modules to be combined into 1 `.js` file for use in the browser.
If I remember correctly, I did try that option and pipe stdout to a .js file, but that gave me a huge
javascript file.

It would be nice if there was a command to tell pulp we are building a library instead of a
run-able program, just including the dependencies my own modules reference.  Is there something
like that?

Thanks for all the help.
I really appreciate it.


Regards
--Rouan

Louis Pilfold

unread,
Sep 26, 2017, 7:04:32 AM9/26/17
to purescript

Hi Rouan

If you're building multiple modules you'll need to output multiple files as in JavaScript one module is one file.

Once you have written your program with these modules you can use browserify, webpack or similar to bundle your code into one file.

Cheers,
Louis


--
You received this message because you are subscribed to the Google Groups "purescript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to purescript+...@googlegroups.com.

Nicholas Wolverson

unread,
Sep 26, 2017, 7:19:38 AM9/26/17
to pures...@googlegroups.com
pulp build --to out.js --skip-entry-point --modules MyExtraModule 

I think this should perform DCE starting from the given set of modules (also check --main), and output to a single file containing a variable binding of the PS object (a map of all built modules), you can append a postscript to that JS file to bind this to a global, or export what you want.

pulp can also help you with browserify - maybe check here https://github.com/purescript-contrib/pulp#reimporting-browserified-bundles

--

rvdalen

unread,
Sep 27, 2017, 1:16:13 AM9/27/17
to purescript
Thanks everyone,

I will try out the suggestions a bit later in the week.

Regards
--Rouan
Reply all
Reply to author
Forward
0 new messages