<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alexander McRae</title>
    <description>The latest articles on DEV Community by Alexander McRae (@mcraealex).</description>
    <link>https://dev.to/mcraealex</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F102250%2F0e7cd84b-a4ee-4038-be9d-072025faea18.jpeg</url>
      <title>DEV Community: Alexander McRae</title>
      <link>https://dev.to/mcraealex</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mcraealex"/>
    <language>en</language>
    <item>
      <title>Setting up Vue and Phoenix 1.5 with vue-cli</title>
      <dc:creator>Alexander McRae</dc:creator>
      <pubDate>Tue, 28 Apr 2020 17:47:30 +0000</pubDate>
      <link>https://dev.to/mcraealex/setting-up-vue-and-phoenix-1-5-with-vue-cli-488c</link>
      <guid>https://dev.to/mcraealex/setting-up-vue-and-phoenix-1-5-with-vue-cli-488c</guid>
      <description>&lt;p&gt;Setting up Vue with the Phoenix framework is oddly difficult, in this guide I&lt;br&gt;
walk through how I have done it. &lt;/p&gt;

&lt;p&gt;At the end of this guide you will have a Phoenix application which serves&lt;br&gt;
the Vue application with hot code reloading using webpack.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why?
&lt;/h2&gt;

&lt;p&gt;Everyone will have a different reasons but I want to use Vue for the &lt;br&gt;
Progressive Web App support.&lt;/p&gt;
&lt;h2&gt;
  
  
  Setup Phoenix
&lt;/h2&gt;

&lt;p&gt;The first thing we are going to do it setup Phoenix. If you want you can use&lt;br&gt;
the &lt;code&gt;--no-webpack&lt;/code&gt; option. I will include it for not since I want admin pages&lt;br&gt;
which use Phoenix's template system.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mix phx.new vue_phx
cd vue_phx
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Setup Vue
&lt;/h2&gt;

&lt;p&gt;Now we create the Vue application with the vue-cli. I have choosen to call mine&lt;br&gt;
app but name it whatever you want.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vue create app
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Go through and select the features you want. Then we create and edit the &lt;br&gt;
&lt;code&gt;vue.config.js&lt;/code&gt; file in the root of the new vue application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// vue_phx/app/vue.config.js&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;path&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;outputDir&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;__dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../priv/app&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will change where you Vue app is outputted. If you choose the no webpack &lt;br&gt;
option then you can change it to "../priv/static" but agian for my admin pages&lt;br&gt;
I keep them seperate.&lt;/p&gt;

&lt;p&gt;One last thing before we move on is to install the webpack-cli&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd app
npm install -D webpack-cli
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Making Phoenix start the webpack watcher
&lt;/h2&gt;

&lt;p&gt;Now in the dev config of the phoenix application we will add another watcher &lt;br&gt;
for the vuejs application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="c1"&gt;# vue_phx/config/dev.ex&lt;/span&gt;
&lt;span class="o"&gt;...&lt;/span&gt;

&lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="ss"&gt;:village&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;VillageWeb&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="no"&gt;Endpoint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="ss"&gt;http:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;port:&lt;/span&gt; &lt;span class="mi"&gt;4000&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="ss"&gt;debug_errors:&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="ss"&gt;code_reloader:&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="ss"&gt;check_origin:&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="ss"&gt;watchers:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="ss"&gt;node:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="s2"&gt;"node_modules/webpack/bin/webpack.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"--mode"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"development"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"--watch-stdin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="ss"&gt;cd:&lt;/span&gt; &lt;span class="no"&gt;Path&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;expand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"../assets"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;__DIR__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="ss"&gt;node:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="s2"&gt;"node_modules/webpack/bin/webpack.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"--mode"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"development"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"--watch-stdin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"--config"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="s2"&gt;"node_modules/@vue/cli-service/webpack.config.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="ss"&gt;cd:&lt;/span&gt; &lt;span class="no"&gt;Path&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;expand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"../app"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;__DIR__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="o"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The first watcher won't be there if you choose the no-webpack option. The second&lt;br&gt;
watcher tells phoenix to start the webpack cli and passes in the &lt;a href="https://cli.vuejs.org/guide/webpack.html#inspecting-the-project-s-webpack-config"&gt;generated config&lt;/a&gt; &lt;br&gt;
as an option. &lt;/p&gt;

&lt;p&gt;Note, this means we will not start the frontend using &lt;br&gt;
&lt;code&gt;npm run serve&lt;/code&gt; as Phoenix will serve the static files and webpack will do the &lt;br&gt;
hot reloading for us.&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting Phoenix to serve the frontend
&lt;/h2&gt;

&lt;p&gt;Now we are going to get phoenix to serve the application at &lt;code&gt;localhost:4000/&lt;/code&gt;.&lt;br&gt;
In &lt;code&gt;lib/vue_phx_web/endpoint.ex&lt;/code&gt; there is a static file server using &lt;br&gt;
&lt;code&gt;Plug.Static&lt;/code&gt;. We are going to add another static file server right below it.&lt;/p&gt;

&lt;p&gt;I change the original aswell to serve &lt;code&gt;at: "/admin"&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="c1"&gt;# vue_phx/lib/vue_phx_web/endpoint.ex&lt;/span&gt;

&lt;span class="o"&gt;...&lt;/span&gt;

&lt;span class="n"&gt;plug&lt;/span&gt; &lt;span class="no"&gt;Plug&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="no"&gt;Static&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="ss"&gt;at:&lt;/span&gt; &lt;span class="s2"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="ss"&gt;from:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:vue_phx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"priv/app"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="ss"&gt;gzip:&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="ss"&gt;only:&lt;/span&gt; &lt;span class="sx"&gt;~w(index.html manifest.json service-worker.js css fonts img js favicon.ico robots.txt)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="ss"&gt;only_matching:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"precache-manifest"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="o"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now if you go to &lt;code&gt;localhost:4000/index.html&lt;/code&gt; you should see your Vue app.&lt;br&gt;
The issue with this is that &lt;code&gt;localhost:4000/&lt;/code&gt; doesn't serve it correctly.&lt;/p&gt;

&lt;p&gt;We can fix that by creating a page controller.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="c1"&gt;# vue_phx/lib/vue_phx_web/controllers/page_controller.ex&lt;/span&gt;

&lt;span class="k"&gt;defmodule&lt;/span&gt; &lt;span class="no"&gt;VuePhxWeb&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="no"&gt;PageController&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="no"&gt;VuePhxWeb&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:controller&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_params&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;conn&lt;/span&gt;
    &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;put_resp_header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"content-type"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"text/html; charset=utf-8"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;Plug&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="no"&gt;Conn&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;send_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"priv/app/index.html"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;halt&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will serve the correct file. Now we just add it to the &lt;code&gt;router.ex&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="c1"&gt;# vue_phx/lib/vue_phx_web/router.ex&lt;/span&gt;

&lt;span class="k"&gt;defmodule&lt;/span&gt; &lt;span class="no"&gt;VuePhxWeb&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="no"&gt;Router&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="no"&gt;VuePhxWeb&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:router&lt;/span&gt;

  &lt;span class="n"&gt;pipeline&lt;/span&gt; &lt;span class="ss"&gt;:browser&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;plug&lt;/span&gt; &lt;span class="ss"&gt;:accepts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"html"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;plug&lt;/span&gt; &lt;span class="ss"&gt;:fetch_session&lt;/span&gt;
    &lt;span class="n"&gt;plug&lt;/span&gt; &lt;span class="ss"&gt;:fetch_flash&lt;/span&gt;
    &lt;span class="n"&gt;plug&lt;/span&gt; &lt;span class="ss"&gt;:protect_from_forgery&lt;/span&gt;
    &lt;span class="n"&gt;plug&lt;/span&gt; &lt;span class="ss"&gt;:put_secure_browser_headers&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="n"&gt;scope&lt;/span&gt; &lt;span class="s2"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;VuePhxWeb&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;pipe_through&lt;/span&gt; &lt;span class="ss"&gt;:browser&lt;/span&gt;

    &lt;span class="n"&gt;get&lt;/span&gt; &lt;span class="s2"&gt;"/*path"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;PageController&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:index&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now &lt;code&gt;localhost:4000/&lt;/code&gt; should serve your Vue application. Let me know if you have&lt;br&gt;
any issues! Shoot me an email at &lt;a href="mailto:mail@alexandermcrae.com"&gt;mail@alexandermcrae.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>vue</category>
      <category>javascript</category>
      <category>phoenix</category>
    </item>
    <item>
      <title>Looking for a mentor</title>
      <dc:creator>Alexander McRae</dc:creator>
      <pubDate>Tue, 18 Sep 2018 05:43:52 +0000</pubDate>
      <link>https://dev.to/mcraealex/looking-for-a-mentor-3dh4</link>
      <guid>https://dev.to/mcraealex/looking-for-a-mentor-3dh4</guid>
      <description>&lt;p&gt;I am looking for someone to help me with a project I am writing. I know exactly what I want to do but am getting confused while implementing it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The project:
&lt;/h2&gt;

&lt;p&gt;The project is a web based game based on &lt;a href="//battlesnake.io"&gt;battlesnake.io&lt;/a&gt; which is a game where people create servers to talk to a main server which displays the game state and contains the logic. My project is to create that main server, with a slight twist! I want mine to be 3D! Originally I thought this would be simple but I have written and deleted it so many times I figure I need some help.&lt;br&gt;
The project will be written in rust, with the front end written either in React with WebGL or yew with WebGL.&lt;/p&gt;

&lt;p&gt;I am looking for someone with experience to mentor me, but by no means hold my hand.&lt;/p&gt;

&lt;p&gt;If you are interested with helping me please contact me! I would love to setup a Skype meeting or a chatroom to discuss the project!&lt;/p&gt;

&lt;p&gt;Thanks for your time!&lt;br&gt;
Sincerly, &lt;br&gt;
Alexander McRae&lt;/p&gt;

</description>
      <category>help</category>
      <category>rust</category>
      <category>webdev</category>
      <category>react</category>
    </item>
  </channel>
</rss>
