Skip to content

Commit 95c2647

Browse files
committed
More documentation updates
1 parent 279e404 commit 95c2647

File tree

4 files changed

+100
-73
lines changed

4 files changed

+100
-73
lines changed

GettingStarted.md

Lines changed: 0 additions & 70 deletions
This file was deleted.

README.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,35 @@ Requirements
1111
Usage
1212
========
1313

14-
Please check the [Getting Started Guide](GettingStarted.md) for usage
14+
Add dependency to your deps in mix.exs:
15+
16+
``` elixir
17+
{:elixir_script, "~> x.x"}
18+
```
19+
20+
Add `elixir_script` to list of mix compilers in mix.exs
21+
Also add `elixir_script` configuration
22+
23+
```elixir
24+
def project do
25+
[
26+
app: :my_app,
27+
# ...
28+
# Add elixir_script as a compilter
29+
compilers: Mix.compilers ++ [:elixir_script],
30+
# Our elixir_script configuration
31+
elixir_script: [
32+
# Entry module. Can also be a list of modules
33+
input: MyEntryModule,
34+
# Output path. Either a path to a js file or a directory
35+
output: "priv/elixir_script/build/Elixir.App.js"
36+
]
37+
]
38+
end
39+
```
40+
41+
Run `mix compile`
42+
1543

1644
Examples
1745
==========

lib/elixir_script.ex

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,71 @@
11
defmodule ElixirScript do
2-
@moduledoc false
2+
@moduledoc """
3+
4+
ElixirScript acts as a mix compiler. This means that when you execute `mix compile`,
5+
ElixirScript's compiler will run as well. Make sure to add ElixirScript to your
6+
list of compilers in mix.exs.
7+
8+
ElixirScript must be told which modules to use as the entry to your ElixirScript application.
9+
This is done by adding an `elixir_script` key to your project configuration whose value is a keyword list of options.
10+
Add an `input` key and make the value either the name of a module or a list of modules
11+
that are the entry modules you wish to compile to JavaScript. ElixirScript will use
12+
those modules to find what other modules and functions it needs to convert to JavaScript.
13+
ElixirScript by default places output in `priv/elixir_script/build`. If you wish to change this,
14+
add an `output` key to your ElixirScript configuration.
15+
16+
An example configuration for a project is shown below
17+
18+
``` elixir
19+
def project do
20+
[
21+
app: :my_app,
22+
version: "0.1.0",
23+
elixir: "~> 1.0",
24+
deps: deps,
25+
# Add elixir_script as a compilter
26+
compilers: Mix.compilers ++ [:elixir_script],
27+
# Our elixir_script configuration
28+
elixir_script: [
29+
# Entry module. Can also be a list of modules
30+
input: MyEntryModule,
31+
# Output path. Either a path to a js file or a directory
32+
output: "priv/elixir_script/build/Elixir.App.js"
33+
]
34+
]
35+
end
36+
```
37+
38+
Available options are:
39+
40+
* `input` (required): The entry module(s) for your application or library
41+
42+
* `output`: The path of the generated JavaScript file. (defaults to `priv/elixir_script/build`)
43+
44+
If path ends in `.js` then that will be the name of the file. If a directory is given,
45+
file will be named `Elixir.App.js`
46+
47+
* `root`: Optional root for imports of FFI JavaScript modules. Defaults to `.`. If using output directly in a browser, you may want to make it something like `/js` or some uri.
48+
49+
50+
Now run `mix compile` and you should see a JavaScript file named `Elixir.App.js` in the `priv/elixir_script/build/` directory. ElixirScript outputs JavaScript in the ES Module format. If your browser supports it, you can include the output in a script tag with the type "module"
51+
52+
```html
53+
<script type="module">
54+
import Elixir from '/js/Elixir.App.js'
55+
const myInitialArgs = []
56+
57+
Elixir.start(Elixir.MyEntryModule, myInitialArgs)
58+
</script>
59+
```
60+
61+
If your browser does not yet support ES modules directly, use a tool such as [webpack](https://webpack.js.org/) or [brunch](http://brunch.io/) to convert it into something that can be used in the browser
62+
63+
### JavaScript Interop
64+
65+
Check out the [JavaScript Interoperability](JavascriptInterop.html) documentation
66+
67+
### Limitations
68+
69+
ElixirScript does not support `receive` or any of OTP at this time.
70+
"""
371
end

mix.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ defmodule ElixirScript.Mixfile do
1414
aliases: aliases(),
1515
test_coverage: [tool: ExCoveralls],
1616
docs: [
17-
extras: ["GettingStarted.md", "JavaScriptInterop.md"]
17+
main: "ElixirScript",
18+
extras: ["JavaScriptInterop.md"]
1819
]
1920
]
2021
end

0 commit comments

Comments
 (0)