A fast alternative to Purescript's `psc-bundle` to be used during development https://github.com/bitc/purescript-bundle-fast
|Latest on Hackage:||0.1.0.1|
This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.
Tested with PureScript version 0.7.1.0
A fast alternative to Purescript's
psc-bundle to be used during development.
With PureScript, you must go through a compilation process. Even if it only takes a few seconds, the lag becomes frustrating when trying to iterate rapidly.
But we can try to bring the compilation time down to almost nothing! This
project manages to do so for the
psc-bundle stage of compilation. It is a
psc-bundle-fast that replaces the official
psc-bundle tool that
comes with PureScript.
psc-bundle-fast should be used only during development. For production you
should still use the official
psc-bundle since it does dead code elimination
and will produce smaller output files.
So how much faster is it? Results for a sample project:
| Command | Time | Output .js Size | --------------- | ------ | --------------- | psc-bundle | 1.458s | 108K | psc-bundle-fast | 0.091s | 464K
That's 16x faster! It's bigger because it contains lots of library code that is
not being used (regular
psc-bundle strips this out). But for local
development, the larger file size has negligible impact on load time, and no
impact on performance.
What about browserify and webpack?
They are even slower than PureScript's
psc-bundle. Feel free to run your own
benchmarks (and tell us the results!)
You need GHC and cabal.
$ cabal update $ cabal install purescript-bundle-fast
psc as usual to compile your program:
$ psc './bower_components/**/src/*.purs' \ --ffi './bower_components/**/src/*.js' \ './src/**/*.purs' \ --ffi './src/**/*.js' \ -o output
Now, just for a comparison, here is how we'd use the regular
$ psc-bundle './output/**/*.js' -m Main --main Main -o app.js
And here is how you would use
psc-bundle-fast instead of the previous step:
$ psc-bundle-fast -i output -m Main --main Main -o app.js
psc-bundle and limitations
It is not able to perform dead code elimination the way that
psc-bundledoes, so it will produce output files that are larger.
It will not detect syntax errors in
foreign.jsfiles. (This is actually an advantage since the error messages that
psc-bundlegenerates are confusing. It's more helpful to see the error that the browser shows).
foreign.jsfiles that use
foreign.jsfiles will load, but if they are executed then an error will be triggered. If you need to a PureScript library that has such
The custom parser that
psc-bundle-fastuses is brittle and relies on the specific format that
pscever makes (even slight) changes to its output then
psc-bundle-fast - Bundles compiled PureScript modules for the browser (fast version, for development) Usage: psc-bundle-fast (-i|--input-dir DIR) [-o|--output FILE] (-m|--module MODULE) [--main MODULE] [-n|--namespace ARG] Available options: --version Show the version number -h,--help Show this help text -i,--input-dir DIR The directory containing the compiled modules. This directory should contain a subdirectory for each compiled module(with the name of the module), and within each of those there should be an index.js (and optional foreign.js) file. The psc compiler usually calls the desired directory "output" -o,--output FILE The output .js file (Default is stdout) -m,--module MODULE Entry point module name(s). All code which is not a transitive dependency of an entry point module will be removed. --main MODULE Generate code to run the main method in the specified module. -n,--namespace ARG Specify the namespace that PureScript modules will be exported to when running in the browser. (default: "PS")