|
| 1 | +# GHCJS |
| 2 | + |
| 3 | +To use GHCJS with stack `>= 0.1.8`, place a GHCJS version in the [`compiler`](https://github.com/commercialhaskell/stack/blob/master/doc/yaml_configuration.md#compiler) field of `stack.yaml`. After this, all stack commands should work with GHCJS, except for `ide`. In particular: |
| 4 | + |
| 5 | +* `stack setup` will install GHCJS from source and boot it, which takes a long time. |
| 6 | +* `stack build` will compile your code to JavaScript. In particular, the generated code for an executable ends up in `$(stack path --local-install-root)/bin/EXECUTABLE.jsexe/all.js` (bash syntax, where `EXECUTABLE` is the name of your executable). |
| 7 | + |
| 8 | +You can also build existing stack projects which target GHC, and instead build them with GHCJS. For example: `stack build --compiler ghcjs-0.1.0.20150924_ghc-7.10.2` |
| 9 | + |
| 10 | +## Example Configurations |
| 11 | + |
| 12 | +### GHCJS (old base) |
| 13 | + |
| 14 | +You can use this resolver for GHCJS (old base) in your `stack.yaml`: |
| 15 | + |
| 16 | +```yaml |
| 17 | +compiler: ghcjs-0.1.0.20150924_ghc-7.10.2 |
| 18 | +compiler-check: match-exact |
| 19 | +``` |
| 20 | +
|
| 21 | +### GHCJS `master` (a.k.a. improved base) |
| 22 | + |
| 23 | +To use the master branch, a.k.a improved base, add the following to your `stack.yaml`: |
| 24 | + |
| 25 | +```yaml |
| 26 | +compiler: ghcjs-0.2.0.20151001_ghc-7.10.2 |
| 27 | +compiler-check: match-exact |
| 28 | +setup-info: |
| 29 | + ghcjs: |
| 30 | + source: |
| 31 | + ghcjs-0.2.0.20151001_ghc-7.10.2: |
| 32 | + url: "https://github.com/fizruk/ghcjs/releases/download/v0.2.0.20151001/ghcjs-0.2.0.20151001.tar.gz" |
| 33 | +``` |
| 34 | + |
| 35 | +or for the 2015-10-29 master branch |
| 36 | +```yaml |
| 37 | +compiler: ghcjs-0.2.0.20151029_ghc-7.10.2 |
| 38 | +compiler-check: match-exact |
| 39 | +setup-info: |
| 40 | + ghcjs: |
| 41 | + source: |
| 42 | + ghcjs-0.2.0.20151029_ghc-7.10.2: |
| 43 | + url: "https://github.com/nrolland/ghcjs/releases/download/v0.2.0.20151029/ghcjs-0.2.0.20151029.tar.gz" |
| 44 | +``` |
| 45 | + |
| 46 | +### Custom installed GHCJS (development branch) |
| 47 | + |
| 48 | +In order to use a GHCJS installed on your path, just add the following to your `stack.yaml`: |
| 49 | + |
| 50 | +```yaml |
| 51 | +compiler: ghcjs-0.2.0_ghc-7.10.2 |
| 52 | +``` |
| 53 | + |
| 54 | +(Or, `ghcjs-0.1.0_ghc-7.10.2` if you are working with an older version) |
| 55 | + |
| 56 | +## Project with both client and server |
| 57 | + |
| 58 | +For projects with both a server and client, the recommended project organization is to put one or both of your `stack.yaml` files in sub-directories. This way, you can use the current working directory to specify whether you're working on the client or server. This will also allow more straightforward editor tooling, once projects like `ghc-mod` and `haskell-ide-engine` support GHCJS. |
| 59 | + |
| 60 | +For example, here's what a script for building both client and server looks like: |
| 61 | + |
| 62 | +```bash |
| 63 | +#!/bin/bash |
| 64 | +
|
| 65 | +# Build the client |
| 66 | +stack build --stack-yaml=client/stack.yaml |
| 67 | +
|
| 68 | +# Copy over the javascript |
| 69 | +rm -f server/static/all.js |
| 70 | +cp $(stack path --stack-yaml=client/stack.yaml --local-install-root)/bin/client.jsexe/all.js server/static/all.js |
| 71 | +
|
| 72 | +# Build the server |
| 73 | +stack build --stack-yaml=server/stack.yaml |
| 74 | +``` |
| 75 | + |
| 76 | +You can also put both the yaml files in the same directory, and have e.g. `ghcjs-stack.yaml`, but this won't work well with editor integrations. |
| 77 | + |
| 78 | +## Using stack without a snapshot |
| 79 | + |
| 80 | +If you don't want to use a snapshot, instead place the ghcjs version in the `resolver` field of your `stack.yaml`. This is also necessary when using stack `< 0.1.8`. |
0 commit comments