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
The intent of this guide is to get you started with ElixirScript. It will give you instructions on using ElixirScript. I will go over the two ways you can use Elixirscript:
4
-
5
-
* As a CLI
6
-
* As a mix dependency
7
-
8
-
### CLI
9
-
10
-
**macOS**: Elixirscript is available via homebrew `brew install elixirscript`. For everyone else, please read below
11
-
12
-
Step 1: Get CLI
13
-
14
-
You can download the elixirscript CLI from the [releases page on github](https://github.com/bryanjos/elixirscript/releases). It is a tar file named elixirscript.tar.gz.
15
-
16
-
Step 2: Untar
17
-
18
-
Next, untar elixirscript.tar.gz
19
-
20
-
tar -xvzf elixirscript.tar.gz
21
-
22
-
You will want to put the bin folder from the uncompressed folder into your path. This should allow you to use the elixirscript CLI.
23
-
24
-
Step 3: Use
25
-
26
-
This is the help output of elixirscript
27
-
28
-
usage: elixirscript <input> [options]
29
-
<input> path to elixir files or
30
-
the elixir code string if passed the -e flag
31
-
options:
32
-
--js-module [<identifer>:<path>] A js module used in your code. ex: React:react
33
-
Multiple can be defined
34
-
-f --format [format] module format of output. options: es (default), common, umd
35
-
-o --output [path] places output at the given path.
36
-
Can be a directory or filename.
37
-
-e --elixir read input as elixir code string
38
-
--full-build informs the compiler to do a full build instead of an incremental one
39
-
-v --version the current version number
40
-
-h --help this message
41
-
42
-
the `<input>` is the elixir code string or file path you want to convert from elixir to javascript. Below is an example of using a code string and turning it into JavaScript
43
-
44
-
$ elixirscript ":atom" -e
45
-
46
-
elixirscript also takes a path to your `.ex` files as well:
47
-
48
-
$ elixirscript "src" -o "dist"
49
-
50
-
If you look in the dist folder you'll see a file called `Elixir.App.js`
51
-
52
-
To start your application import the bundle according to whichever module format was selected and
53
-
then call start giving it the module and the initial args.
54
-
55
-
Ex. If you have a module like so
56
-
```elixir
57
-
defmoduleExampledo
58
-
start(type, args) do
59
-
:console.log("Hello, world")
60
-
end
61
-
end
62
-
```
63
-
64
-
You would start it like so
65
-
66
-
```javascript
67
-
//ES module example
68
-
importElixirfrom'./Elixir.App'
69
-
Elixir.start(Elixir.Example, [])
70
-
```
71
-
72
-
### Mix dependency
3
+
The intent of this guide is to get you started with ElixirScript. It will give you instructions on using ElixirScript.
73
4
74
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.
75
6
76
7
Add dependency to your deps in mix.exs:
77
8
78
9
```elixir
79
-
{:elixir_script, "~> 0.26"}
10
+
{:elixir_script, "~> 0.29"}
80
11
```
81
12
82
-
Elixirscript uses default input, 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
+
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.
83
14
84
15
```elixir
85
16
defprojectdo
@@ -89,7 +20,7 @@ Elixirscript uses default input, output and module formats if options are not gi
89
20
elixir:"~> 1.0",
90
21
deps: deps,
91
22
elixir_script: [
92
-
input:"lib/elixirscript",
23
+
input:MyEntryModule,
93
24
output:"priv/elixirscript/Elixir.App.js",
94
25
format::es,
95
26
js_modules: [
@@ -98,14 +29,14 @@ Elixirscript uses default input, output and module formats if options are not gi
98
29
{Phoenix, "phoenix", default:false}
99
30
]
100
31
],
101
-
compilers:[:elixir_script]++Mix.compilers
32
+
compilers:Mix.compilers++[:elixir_script]
102
33
]
103
34
end
104
35
```
105
36
106
37
Available options are:
107
38
108
-
*`input`: The folder to look for Elixirscript files in. (defaults to `lib/elixirscript`)
39
+
*`input`: The entry module(s) for your application or library
109
40
110
41
*`output`: The path of the generated JavaScript file. (defaults to `priv/elixirscript`)
111
42
@@ -126,20 +57,8 @@ Available options are:
126
57
127
58
### Macros
128
59
129
-
Elixirscript supports public macros. Private macros are currently unsupported.
60
+
Elixirscript supports all macros
130
61
131
62
### JavaScript Interop
132
63
133
64
Check out the [JavaScript Interoperability](JavaScriptInterop.html) documentation
134
-
135
-
#### Frontend Project Boilerplate
136
-
137
-
There is an [elixirscript frontend boilerplate project](https://github.com/elixirscript/elixirscript-project-boilerplate). This setup uses gulp and webpack to build and bundle assets.
138
-
139
-
#### elixirscript-brunch
140
-
141
-
There is an Brunch plugin, [elixirscript-brunch](https://www.npmjs.com/package/elixirscript-brunch).
142
-
143
-
#### elixirscript-loader
144
-
145
-
There is also a webpack loader, [elixirscript-loader](https://www.npmjs.com/package/elixirscript-loader).
0 commit comments