elbasti

elbasti

Phoenix + Vue.js CLI: How do you manage the build and development pipelines?

Hi folks,

I’m working on a greenfield webapp. The stack I’d like to try is Vue on top of Phoenix. I’m not new to vue, but I’m new to Phoenix.

I wonder how you all have been addressing the js build chain at development & build time.

I’d love to be able to use the vue cli as much as possible. JS tooling is definitely not my strong suit and so far I’ve found it incredibly useful, with super sane defaults and really cool features (ex, modern mode )

However, one side effect of using vue-cli is that webpack config is kind of abstracted away.

Right now I’m thinking about structuring my project as follows:

  1. Start a new phoenix project with --no-webpack ;
  2. Start a vue project using vue-cli-service , with these two changes:
  • priv/static should be the build target
  • lib/myapp/templates/layout/app.html.eex should be the index_path for vue-cli-service

Would this work? Anyone here using vue & phoenix have a similar setup?

As well, how do you handle developing the vue component of your app (ie, leveraging vue-cli-service serve ) with such a setup?

Many thanks, loving phoenix so far.

Marked As Solved

sribe

sribe

In dev, I have a dev (Node) server serving the Vue app, which talks to the Phoenix server, websockets in my case, but could just a well be a REST API. In production, the Phoenix server just serves the Vue app as static assets.

I don’t. I create the Phoenix app with --no-html.

Also Liked

mikemccall

mikemccall

I don’t. If I’m using the cli I use it standalone. The vue cli doesn’t do a good job integrating with existing frameworks, I believe this is an oversight and it will be resolved but it doesn’t seem to be a priority. There are some open issues and ongoing discussions around this. I have a hard time accepting the whole “Just output the index.html file where your backend app will server it” There are many cases where people don’t want to replace the entire rendered page with vue. I love vue as a frontend framework because you can use it in many different forms. From adding it from the cdn and sprinkle in some components all the way to full SPA. The vue-cli really pushes towards SPA. Now that phoenix uses webpack adding vue (and using single file components) is as easy as adding the vue loader.

It’s actually fairly straight forward!

cd assets && npm install --save-dev vue-loader

Update the webpack.config.js

...
{
  test: /\.vue$/,
    use: {
      loader: 'vue-loader'
    }
  },
...

In your app.js

import Vue from 'vue'
import App from './src/App.vue'

new Vue({
  el: '#app',
  render: (h) => h(App)
})

Any page you want to render vue just add the appropriate tag:

For example myapp_web/templates/page/index.html.eex

<div id="app"></div>

At this point nothing stops you from installing and using the vue-router or vuex. Customize and use at will.

11
Post #8
peerreynders

peerreynders

No. With that setup Phoenix doesn’t serve any of the Vue app’s asset’s - it strictly functions as an independent JSON server.

I had a Vue example for Phoenix 1.3 using the app.html.eex but the consensus seems to be to keep Phoenix/Vue separate so that using Nuxt.js remains an option.

For React there is elixir_react_render

but there is nothing like that for Vue yet.


Some “Phoenix as a JSON API server” resources:

Harvested from:

josvme

josvme

I don’t know if this is going to be useful to you. But I will try anyway :D.

I have some experience using Vue and Phoenix. I chose Vue for the same reason that it will be easier to convert to a mobile app at some point. say using Nativescript. . I am also not a fan of Javascript, so I use Vue with Typescript, which works amazingly well.

Now coming to development, I am a fan of separating frontend from backend. This allows independent development of both and facilitates decoupling. Deploying Vue with Phoenix is easy. I just compile Vue to a single JS file and serve it using Nginx. So my index page shows Vue app. Vue calls into Phoenix using /api url. All calls to /api is redirected by nginx to my Phoenix listening on say port 4000. When combined with Docker, the deployment is also very pleasant. In case you are interested you can also check out my blog post for more info. Have a nice day :slight_smile:

Where Next?

Popular in Questions Top

nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52673 488
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement