You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: GettingStarted.md
+18-10Lines changed: 18 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,20 @@
1
-
# Getting Started with ElixirScript
1
+
# Getting Started
2
2
3
3
The intent of this guide is to get you started with ElixirScript. It will give you instructions on using ElixirScript.
4
4
5
-
Adding Elixirscript to your mix project gives you the ability to add it to your list of mix compilers. This means when you `mix compile`, Elixirscript will compile your code as well.
5
+
Adding ElixirScript to your mix project gives you the ability to add it to your list of mix compilers. This means when you `mix compile`, ElixirScript will compile your code as well.
6
6
7
7
Add dependency to your deps in mix.exs:
8
8
9
9
```elixir
10
10
{:elixir_script, "~> 0.30"}
11
11
```
12
12
13
-
Elixirscript uses default output and module formats if options are not given. If you wish to change any or all options, add an `elixir_script` key to your project configuration.
13
+
Next make sure to add ElixirScript to your list of compilers in mix.exs.
14
+
15
+
ElixirScript must be told which modules to use as the entry to your ElixirScript application. This is done by adding an `elixir_script` key to your project configuration. This must be a keyword list. Add an `input` key and make the value either the name of a module or a list of modules that are the entry modules you wish to compile to JavaScript. ElixirScript will use those modules to find what other modules and functions it needs to convert to JavaScript. ElixirScript by default places output in `priv/elixir_script/build`. If you wish to change this, add an `output` key to your ElixirScript configuration.
16
+
17
+
An example configuration for a project is shown below
14
18
15
19
```elixir
16
20
defprojectdo
@@ -19,18 +23,22 @@ Elixirscript uses default output and module formats if options are not given. If
19
23
version:"0.1.0",
20
24
elixir:"~> 1.0",
21
25
deps: deps,
26
+
# Add elixir_script as a compilter
27
+
compilers:Mix.compilers++ [:elixir_script],
28
+
# Our elixir_script configuration
22
29
elixir_script: [
30
+
# Entry module. Can also be a list of modules
23
31
input:MyEntryModule,
32
+
# Output path. Either a path to a js file or a directory
24
33
output:"priv/elixir_script/build/Elixir.App.js"
25
-
],
26
-
compilers:Mix.compilers++ [:elixir_script]
34
+
]
27
35
]
28
36
end
29
37
```
30
38
31
39
Available options are:
32
40
33
-
*`input`: The entry module(s) for your application or library
41
+
*`input` (required): The entry module(s) for your application or library
34
42
35
43
*`output`: The path of the generated JavaScript file. (defaults to `priv/elixir_script/build`)
36
44
@@ -53,10 +61,10 @@ Now run `mix compile` and you should see a JavaScript file named `Elixir.App.js`
53
61
54
62
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
55
63
56
-
### Macros
57
-
58
-
Elixirscript supports all macros
59
-
60
64
### JavaScript Interop
61
65
62
66
Check out the [JavaScript Interoperability](JavascriptInterop.html) documentation
67
+
68
+
### Limitations
69
+
70
+
ElixirScript does not support `receive` or any of OTP at this time.
ElixirScript calls JavaScript modules through a Foreign Function Interface (FFI). A foreign module is defined by creating a new module and adding `use ElixirScript.FFI` to it.
20
+
ElixirScript calls JavaScript modules through a Foreign Function Interface (FFI). A foreign module is defined by creating a new Elixir module and adding `use ElixirScript.FFI` to it.
21
21
22
22
Here is an example of a foreign module for a JSON module
0 commit comments