Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ $ elm-server path/to/Main.elm
-V, --version output the version number
-o, --output <path> Path to elm-make output [index.html].
-s, --start-path <path> Initial path when opening browser.
-a. --spa Set to something to enable single page application mode
-w, --watch <directory> Path to served directory. Defaults
to directory of output file path.
```
Expand Down Expand Up @@ -59,6 +60,13 @@ $ elm-server src/elm/Main.elm \
--start-path html/index.html
```

###### spa
When you have a Single Page Application with routing on the client side, this mode is for you. It uses the [connect-history-api-fallback](https://github.com/bripkens/connect-history-api-fallback) library.

It currently assumes that you are using index.html as the entry point for your app.



#### Programmatic Usage

In addition to providing a cli, elm-server can also be called programmatically.
Expand Down
4 changes: 3 additions & 1 deletion bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ commander
.version(version)
.option('-o, --output <path>', 'Path to elm-make output [index.html].')
.option('-s, --start-path <path>', 'Initial path when opening browser.')
.option('-a, --spa <true>', 'Set to whatever to enable spa mode.')
.usage('[options] <inputFile> [inputFiles...]');

var descriptionWidth = 35;
Expand All @@ -34,5 +35,6 @@ if (!commander.args.length) {
elmServer(commander.args, {
output: commander.output,
startPath: commander.startPath,
watch: commander.watch
watch: commander.watch,
spa: commander.spa
});
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
var browserSync = require('browser-sync');
var chokidar = require('chokidar');
var historyApiFallback = require('connect-history-api-fallback');
var spawn = require('child_process').spawn;
var platform = require('elm/platform');
var path = require('path');
Expand All @@ -27,6 +28,8 @@ module.exports = function elmServer(inputFilesArg, optsArg) {
opts.output;

var watch = opts.watch || path.dirname(outputFile);
var isSpa = opts.spa || false;

var startPath =
opts.startPath ||
(path.extname(outputFile) === '.html' ?
Expand All @@ -47,7 +50,10 @@ module.exports = function elmServer(inputFilesArg, optsArg) {
.on('change', elmMake);

return browserSync({
server: watch,
server: {
baseDir: watch,
middleware: isSpa ? [ historyApiFallback() ] : []
},
watchOptions: {
ignored: /(elm-stuff|\.elm)/
},
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"dependencies": {
"browser-sync": "^2.10.1",
"chokidar": "^1.4.1",
"connect-history-api-fallback": "^1.1.0",
"commander": "2.8.0",
"elm": "^0.16.0",
"lodash.chunk": "^3.0.1"
Expand Down