Skip to content

Commit 1df4948

Browse files
committed
Update phoenix guide
1 parent 9e2fc5a commit 1df4948

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

content/guide/using-with-phoenix.md

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ title = "using with phoenix"
55

66
This guide will walk through setting up a Phoenix project with Elixirscript. This guide assumes you have already created a Phoenix project
77

8-
**NOTE**: This guide covers Phoenix 1.2. It will be updated when Phoenix 1.3 is released
8+
**Update: 2017-08-15**: This guide has been updated to cover both ElixirScript 0.30 and Phoenix 1.3
99

1010
Update your mix.exs file to add the current version of elixirscript to your dependencies:
1111

1212
```elixir
1313
defp deps do
1414
[
1515
#other deps
16-
{:elixir_script, "~> x.x.x"}
16+
{:elixir_script, "~> x.x"}
1717
]
1818
```
1919

@@ -31,58 +31,51 @@ def project do
3131
version: "0.0.1",
3232
elixir: "~> 1.2",
3333
elixirc_paths: elixirc_paths(Mix.env),
34-
compilers: [:phoenix, :gettext, :elixir_script] ++ Mix.compilers,
34+
compilers: [:phoenix, :gettext] ++ Mix.compilers ++ [:elixir_script],
3535
build_embedded: Mix.env == :prod,
3636
start_permanent: Mix.env == :prod,
3737
deps: deps(),
3838
elixir_script: [
39-
input: "web/static/elixirscript",
40-
output: "web/static/js/build"
39+
input: MyApp.App,
40+
output: "assets/js/build"
4141
]
4242
]
4343
end
4444
```
4545

46-
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.
4749

48-
Next, update the watcher configuration to use the Elixirscript watcher:
49-
50-
```elixir
51-
watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin",
52-
cd: Path.expand("../", __DIR__)], mix: ["elixirscript.watch"]]
53-
```
54-
55-
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
5851

5952
```bash
60-
touch web/static/elixirscript/app.ex
53+
touch lib/my_app_frontend/app.ex
6154
```
6255

6356
For this example, write a simple module that will write `Hello, world` to the console on start:
6457

6558
```elixir
66-
defmodule App do
59+
defmodule MyApp.App do
6760

6861
def start(_type, _args) do
69-
:console.log("Hello, world")
62+
IO.puts("Hello, world")
7063
end
7164

7265
end
7366
```
7467

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:
7669

7770
```javascript
78-
import Elixir from './build/Elixir.App';
79-
Elixir.start(Elixir.App, [])
71+
import Elixir from './build/elixirscript.build.js';
72+
Elixir.start(Elixir.MyApp.App, [])
8073
```
8174

8275
The empty array is list of initial arguments for your app.
8376

8477

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.
8679

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
8881

content/post/elixirscript-0.30.0-released.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
+++
22
title = "ElixirScript 0.30.0 Released"
3-
date = 2017-08-09T00:29:03-05:00
3+
date = 2017-08-15T00:29:03-05:00
44
draft = true
55
+++
66

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.
88

99
## Foreign Function Interface (FFI)
1010

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.
1214

1315
Our Elixir module, `MyApp.Http`
1416
```elixir
@@ -35,15 +37,15 @@ export default {
3537
}
3638
```
3739

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.
3941

4042
With the above in place, you can call functions on `MyApp.Http` as you would any other Elixir module.
4143

4244
For more information, check the documentation for `ElixirScript.FFI`.
4345

4446
## Dependencies
4547

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.
4749

4850
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).
4951

@@ -55,14 +57,16 @@ Calls to Erlang functions that the Elixir standard library make have to be reimp
5557

5658
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.
5759

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.
5961

6062
## Limitations
6163

6264
`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.
6365

6466
## Conclusion
6567

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+
6670
For more information regarding changes, please check the [changelog](https://github.com/elixirscript/elixirscript/blob/master/CHANGELOG.md).
6771

6872
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
7276
For more on JavaScript Interoperability, check out the [JavaScript interoperability documentation](https://hexdocs.pm/elixir_script/JavaScriptInterop.md)
7377

7478
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

Comments
 (0)