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
Elixirscript by default will looks for input in the `lib/elixirscript` directory. It will also by default output to `priv/elixirscript`. Update the input directory to `web/static/elixirscript`. Update the output directory to `web/static/js/build`. This lets it tie into Brunch's pipeline.
46
+
Make the `input` the entry point module of your ElixirScript App. Here is will be `MyApp.App` which we will
47
+
define later. Next, add the `output` to the configuration and make it `"assets/js/build"`. By default the output
48
+
goes to `priv/elixir_script/build`, but we want to place our output somewhere that our asset compilation process can pick it up and bundle it with any other JavaScript.
47
49
48
-
Next, update the watcher configuration to use the Elixirscript watcher:
Whenever your Elixirscript code changes, the elixirscript compiler will recompile it.
56
-
57
-
Create `app.ex` in the `web/static/elixirscript` directory
50
+
Create `app.ex` in the `lib/my_app_frontend` directory
58
51
59
52
```bash
60
-
touch web/static/elixirscript/app.ex
53
+
touch lib/my_app_frontend/app.ex
61
54
```
62
55
63
56
For this example, write a simple module that will write `Hello, world` to the console on start:
64
57
65
58
```elixir
66
-
defmoduleAppdo
59
+
defmoduleMyApp.Appdo
67
60
68
61
defstart(_type, _args) do
69
-
:console.log("Hello, world")
62
+
IO.puts("Hello, world")
70
63
end
71
64
72
65
end
73
66
```
74
67
75
-
Finally, update `web/static/js/app.js` to start your Elixirscript app:
68
+
Finally, update `assets/js/app.js` to start your Elixirscript app:
76
69
77
70
```javascript
78
-
importElixirfrom'./build/Elixir.App';
79
-
Elixir.start(Elixir.App, [])
71
+
importElixirfrom'./build/elixirscript.build.js';
72
+
Elixir.start(Elixir.MyApp.App, [])
80
73
```
81
74
82
75
The empty array is list of initial arguments for your app.
83
76
84
77
85
-
If you run `mix compile`, you should see a JavaScript file, `Elixir.App.js` in your `web/static/js/build` directory.
78
+
If you run `mix compile`, you should see a JavaScript file, `elixirscript.build.js` in your `assets/js/build` directory.
86
79
87
-
If you run `mix phoenix.server`, open your browser, and then open your console, you should see `Hello, world`. Any changes should cause a reload
80
+
If you run `mix phx.server`, open your browser, and then open your console, you should see `Hello, world`. Any changes should cause a recompilation of your ElixirScript code and a reload of the browser
Copy file name to clipboardExpand all lines: content/post/elixirscript-0.30.0-released.md
+10-8Lines changed: 10 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,16 @@
1
1
+++
2
2
title = "ElixirScript 0.30.0 Released"
3
-
date = 2017-08-09T00:29:03-05:00
3
+
date = 2017-08-15T00:29:03-05:00
4
4
draft = true
5
5
+++
6
6
7
-
ElixirScript 0.30 is a large release with lots of changes. It includes a rewrite of the compiler, a change in JavaScript interoperability and much more. This is also the first version to require Erlang 20 and Elixir 1.5, compiled with Erlang 20. Writing ElixirScript projects feel more like writing a normal Elixir project. These changes make this the best release of ElixirScript so far! This is a great point to give ElixirScript a try for yourself. This post will describe the major changes in this version.
7
+
ElixirScript 0.30 is a large release with lots of changes. It includes a rewrite of the compiler, a change in JavaScript interoperability and much more. This is also the first version to require Erlang 20 and Elixir 1.5, compiled with Erlang 20. ElixirScript can compile your Elixir code and dependencies into JavaScript, with some [limitations](#limitations). These changes make this the best release of ElixirScript so far! This is a great point to give ElixirScript a try for yourself. This post will describe the major changes.
8
8
9
9
## Foreign Function Interface (FFI)
10
10
11
-
JavaScript interoperability has changed in this version. ElixirScript now interacts with JavaScript using an FFI. This allows for a stricter barrier between Elixir code and JavaScript. It also allows for the ability to make packages designed to work with ElixirScript. Another benefit is that there are far fewer warnings during compilation time. As an example let's create an FFI module for some HTTP specific functions we want to use from JavaScript. An FFI module has 2 parts: the Elixir module and the corresponding JavaScript module.
11
+
JavaScript interoperability has changed. ElixirScript now interacts with JavaScript using an FFI. This means there is a stricter barrier between Elixir and JavaScript. The FFI allows the ability to make packages designed to work with ElixirScript. Another benefit is that there are far fewer warnings during compilation time. As an example let's create an FFI module for some HTTP specific functions we want to use from JavaScript.
12
+
13
+
An FFI module has 2 parts: the Elixir module and the corresponding JavaScript module.
12
14
13
15
Our Elixir module, `MyApp.Http`
14
16
```elixir
@@ -35,15 +37,15 @@ export default {
35
37
}
36
38
```
37
39
38
-
ElixirScript depends on the JavaScript module being at a certain path. It will look for the JavaScript module either at `priv/elixir_script/my_app/http.js` or `priv/elixir_script/my_app.http.js`. If your code uses the FFI module, during compilation ElixirScript copies the js file along side the compilation output. The generated output imports the js file.
40
+
ElixirScript depends on the JavaScript module being at a certain path. It will look for the JavaScript module either at `priv/elixir_script/my_app/http.js` or `priv/elixir_script/my_app.http.js`. If your code uses the FFI module, during compilation ElixirScript copies the js file along side the compilation output. The generated output imports the js file. The JavaScript module must be an ES module that exports a default object containing the functions you want to use.
39
41
40
42
With the above in place, you can call functions on `MyApp.Http` as you would any other Elixir module.
41
43
42
44
For more information, check the documentation for `ElixirScript.FFI`.
43
45
44
46
## Dependencies
45
47
46
-
ElixirScript can compile your project's dependencies to JavaScript. This means you can use many of your favorite Hex packages in ElixirScript code. It is also now possible to create packages that ElixirScript code can use. These are normal mix projects which may or may not have FFI modules with their corresponding JavaScript files.
48
+
ElixirScript can compile your project's dependencies to JavaScript. This means you can use many of the packages available in Hex. It is also possible to create ElixirScript-specific packages. These are normal mix projects which may or may not have FFI modules with their corresponding JavaScript files.
47
49
48
50
If creating a Hex package for ElixirScript, please prepend `elixir_script` to your package name. This is so that it is clear your package is to be use with ElixirScript. For example, a React package would be named `elixir_script_react`. [Here is an example](https://github.com/elixirscript/elixirscript_react).
49
51
@@ -55,14 +57,16 @@ Calls to Erlang functions that the Elixir standard library make have to be reimp
55
57
56
58
ElixirScript now only works as a mix compiler. This means there will no longer be an escript for download and plugins for Brunch and Webpack will no longer work with this and future versions.
57
59
58
-
ElixirScript now only supports output of ES modules. This is mainly so that there is no confusion about how to implement the JavaScript portion of FFI modules.
60
+
ElixirScript now only supports output of ES modules.
59
61
60
62
## Limitations
61
63
62
64
`receive` is still not supported. When ElixirScript encounters a `receive` call during compilation, the compiler will show a warning, but will continue. During runtime these calls will throw an error. With `receive` not yet supported, this also means most of OTP is not supported as well.
63
65
64
66
## Conclusion
65
67
68
+
Finally, I want to give a great big thanks to the Elixir Core Team! Thanks for making the updates in Erlang and Elixir that allowed ElixirScript's progress to continue. And thank you for being available to answer questions and to give great advice!
69
+
66
70
For more information regarding changes, please check the [changelog](https://github.com/elixirscript/elixirscript/blob/master/CHANGELOG.md).
67
71
68
72
For more on getting started with ElixirScript, check the [ElixirScript documentation](https://hexdocs.pm/elixir_script/ElixirScript.html)
@@ -72,5 +76,3 @@ For more on FFI, and other things, check out the [FFI documentation](https://hex
72
76
For more on JavaScript Interoperability, check out the [JavaScript interoperability documentation](https://hexdocs.pm/elixir_script/JavaScriptInterop.md)
73
77
74
78
For an example of an ElixirScript app, check out the [Todo Example App](https://github.com/elixirscript/todo-elixirscript)
75
-
76
-
Finally, I want to give a great big thanks to the Elixir Core Team! Thanks for making the updates in Erlang and Elixir that allowed ElixirScript's progress to continue. And thank you for being available to answer questions and to give great advice!
0 commit comments