Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/wking-io/elm-live
Browse files Browse the repository at this point in the history
  • Loading branch information
wking-io committed Oct 23, 2018
2 parents 0f475bb + 4718956 commit e381907
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
35 changes: 25 additions & 10 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,33 +87,42 @@ We also watch all `*.elm` files in the current directory and its subdirectories.

## OPTIONS

#### `--port=PORT`
#### `-p, --port [PORT]`
Set the port to start the server at. If the port is taken, we’ll use the next available one. `PORT` should be a valid port number. Default: `8000`.

#### `--path-to-elm=PATH`
#### `-e, --path-to-elm [PATH]`
An absolute or relative path to `elm`. If you’ve installed _elm-platform_ locally with _npm_ (`npm install --save-dev elm`), you’ll likely want to set this to `node_modules/.bin/elm`. Default: `elm`.

#### `--host=HOSTNAME|IP`
#### `-h, --host [HOSTNAME|IP]`
Set the host interface to attach the server to. Default: `localhost`.

#### `--dir=PATH`
#### `-d, --dir=PATH`
The base for static content. Default: `.`.

#### `--open`
#### `-o, --open`
We’ll open the app in your default browser as soon as the server is up.

#### `--no-recover`
#### `-r, --no-recover`
When _elm make_ encounters a compile error, we keep _elm-live_ running and give you time to fix your code. Pass `--no-recover` if you want the server to exit immediately whenever it encounters a compile error.

#### `--pushstate`
#### `-u, --pushstate`
Serve `index.html` on 404 errors. This lets us use client-side routing in Elm. For instance, we can have a URL like `http://localhost:8000/account` get handled by the Elm _navigation_ package instead of failing with a 404 error.

#### `--before-build=EXECUTABLE`
#### `-s, --start-page [STARTPAGE]`
A custom html file to serve other than the default `index.html`.

#### `-x, --proxyPrefix [PREFIX]`
Proxy requests to paths starting with `prefix` to another server. Requires `--proxyHost` and should be a string like `/api`. Defaults to not proxying

#### `-y, --proxyHost`
Proxy requests to another server running at `host`. Requires `--proxyHost` and should be a full URL, eg. `http://localhost:9000`. Defaults to not proxying

#### `-b, --before-build [EXECUTABLE]`
Run `EXECUTABLE` before every rebuild. This way you can easily use other tools like _elm-css_ or _browserify_ in your workflow.

Heads up! At the moment, we only allow running a single executable without parameters. If you need more than that, please give us a shout at https://git.io/elm-live.before-build-args.

#### `--after-build=EXECUTABLE`
#### `-a, --after-build [EXECUTABLE]`
Just like `--before-build`, but runs after `elm make`.

#### `--help`
Expand All @@ -136,12 +145,18 @@ $ elm-live src/Main.elm --open

### Use a custom HTML file

This command tells `elm make` to compile your elm code to a file named `elm.js` in the folder you are running the command from. From there you just need to include the script in your index.html as shown in the Elm guide here: https://guide.elm-lang.org/interop/
This command tells `elm make` to compile your elm code to a file named `elm.js` in the folder you are running the command from. From there you just need to include the script in default file of index.html as shown in the Elm guide here: https://guide.elm-lang.org/interop/

```sh
$ elm-live src/Main.elm --open -- --output=elm.js
```

To specify an HTML file other than the default, you can use the `--start-page` flag. This is an easy way to avoid `elm make` accidentally overriding your custom HTML.

```sh
$ elm-live src/Main.elm --open --start-page=custom.html -- --output=elm.js
```

### Support client-side routing in Elm

This command tells the server to always serve up the index.html no matter what the URL is. This allows Elm to handle the routing clientside. Note: this option is a must when you are using `Browser.Navigation`
Expand Down
1 change: 1 addition & 0 deletions bin/elm-live.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ program
.option('-o, --open [open]', 'Open in browser when server starts.', false)
.option('-r, --no-recover [no-recover]', `Stop server when ${chalk.cyan.underline('elm make')} runs into an issue.`)
.option('-u, --pushstate [pushstate]', `Forces the index.html file to always be served. Must be used when building with ${chalk.cyan.underline('Browser.application')}.`, false)
.option('-s, --start-page [start-page]', 'Specify a custom HTML file', 'index.html')
.option(
'-x, --proxyPrefix [prefix]',
'Proxy requests to paths starting with `prefix` to another server. Requires `--proxyHost` and should be a string like `/api`. Defaults to not proxying'
Expand Down
5 changes: 3 additions & 2 deletions source/elm-live.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ module.exports = (argv, options) => {
pushstate: argv.pushstate || false,
proxyPrefix: argv.proxyPrefix || false,
proxyHost: argv.proxyHost || false,
elmMakeArgs: argv.args || []
elmMakeArgs: argv.args || [],
startPage: argv.startPage || "index.html"
},
(argv.beforeBuild ? { beforeBuild: argv.beforeBuild } : {}),
(argv.afterBuild ? { afterBuild: argv.afterBuild } : {})
Expand Down Expand Up @@ -166,7 +167,7 @@ ${chalk.dim('elm-live:')}
pushstate: args.pushstate,
proxyPrefix: args.proxyPrefix,
proxyHost: args.proxyHost,
startPage: 'index.html'
startPage: args.startPage
})

serverStarted = true
Expand Down

0 comments on commit e381907

Please sign in to comment.