<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tom Vance on Medium]]></title>
        <description><![CDATA[Stories by Tom Vance on Medium]]></description>
        <link>https://medium.com/@TomVance?source=rss-91a8493b0c2b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QwG20Y_lFawJUCcujA7fKg.jpeg</url>
            <title>Stories by Tom Vance on Medium</title>
            <link>https://medium.com/@TomVance?source=rss-91a8493b0c2b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 20:42:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@TomVance/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Local domains with HTTPS and Docker compose]]></title>
            <link>https://medium.com/@TomVance/local-domains-with-https-469036775818?source=rss-91a8493b0c2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/469036775818</guid>
            <dc:creator><![CDATA[Tom Vance]]></dc:creator>
            <pubDate>Wed, 06 Jul 2022 15:43:17 GMT</pubDate>
            <atom:updated>2022-07-06T15:47:02.400Z</atom:updated>
            <content:encoded><![CDATA[<p>How to run HTTPS in development with Nginx and Docker</p><p>Literally every time I build anything I seem to forget how to do this, so mainly this is for future me when I without a doubt need to google this again.</p><p>Most of the web now requires SSL for basically everything, browsers will shout at you third parties may not accept the http-only domains (Shopify doesn’t for webhooks). Thats all well and good in production but we build things on our local machines, so how do I get a SSL certificate to work with something like tom.dev ?</p><h3>Running NGINX as a reverse proxy</h3><p>The easiest way I have found to do all of this is to use Docker and NGINX as a reverse proxy.</p><p>First up create a docker-compose.yml file with the following setup:</p><pre># docker-compose.yml</pre><pre>version: &#39;3.1&#39;</pre><pre>services:<br>  nginx:<br>    image: nginx:latest<br>    ports:<br>      - 80:80<br>      - 443:443<br>    restart: always<br>    volumes:<br>      - ./nginx/conf/:/etc/nginx/conf.d/:ro<br>      - ./nginx/certs:/etc/nginx/ssl</pre><p>And create a the directories for the volumes:</p><pre>docker-compose.yml<br>nginx/<br>   conf/<br>   certs/</pre><p>If you now run docker compose up you should have nginx up and running.</p><h3>Configure your proxy</h3><p>Next we need to tell Nginx how to route our traffic, this is all controlled with configuration files:</p><p>Create a new file with the following content at nginx/conf/tom.conf</p><pre># nginx/conf/tom.conf</pre><pre>server {<br>    listen 80;<br>    listen [::]:80;</pre><pre>server_name tom.dev;</pre><pre>location / {<br>        proxy_set_header   X-Forwarded-For $remote_addr;<br>        proxy_set_header   Host $http_host;<br>        proxy_pass         <a href="http://host.docker.internal:5001/">http://host.docker.internal:5001</a>;<br>    }<br>}</pre><pre>server {<br>    listen 443 ssl http2;<br>    listen [::]:443 ssl http2;</pre><pre>server_name tom.dev;</pre><pre>ssl_certificate /etc/nginx/ssl/_wildcard.tom.dev.pem;<br>    ssl_certificate_key /etc/nginx/ssl/_wildcard.tom.dev-key.pem;<br>    <br>    location / {<br>        proxy_set_header   X-Forwarded-For $remote_addr;<br>        proxy_set_header   Host $http_host;<br>        proxy_pass         <a href="http://host.docker.internal:5001/">http://host.docker.internal:5001</a>;<br>    }<br>}</pre><h3>Generate some SSL certificates</h3><p>Im sure you can do this manually by … eh there is a great tool for this Mkcert.</p><p><a href="https://github.com/FiloSottile/mkcert">GitHub - FiloSottile/mkcert: A simple zero-config tool to make locally trusted development certificates with any names you&#39;d like.</a></p><p>Install that and then do the following:</p><pre>cd nginx/certs<br>mkcert &quot;*.tom.dev&quot;</pre><p>That will then generate certificates for the tom.dev domain and any subdomains you add later.</p><h3>Tell your PC where to go</h3><p>The final thing you need to do is tell you PC to direct all traffic back to your localhost. Thats done via your hosts file:</p><pre>vi /etc/hosts</pre><pre>127.0.0.1 tom.dev</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=469036775818" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying a React application to Amazon s3 with Github actions.]]></title>
            <link>https://medium.com/swlh/building-and-deploying-your-first-react-app-e0b8d1e3eb72?source=rss-91a8493b0c2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0b8d1e3eb72</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[s3-bucket]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Tom Vance]]></dc:creator>
            <pubDate>Fri, 01 May 2020 18:58:13 GMT</pubDate>
            <atom:updated>2020-05-02T21:36:59.730Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1VQBKqq0FkiTSsT3RZYuBg.png" /></figure><p>Short write up on building and deploying React-based applications to Amazon s3 using Github actions.</p><h3>Create your React application</h3><p>The first thing we’re going to need is a React application that we can deploy. For the sake of simplicity lets just go ahead and use create-react-app to build a hello world app.</p><pre>$ npx create-react-app hello-github-actions</pre><p><a href="https://reactjs.org/docs/create-a-new-react-app.html">Create a New React App - React</a></p><h3>Get your code to Github</h3><p>Next we need a Github repository for our codebase, if you’ve not got a Github account already go ahead and signup for one here: <a href="https://github.com/join">https://github.com/join</a></p><p>Create our new repository and push up all of our code to it:</p><pre>$ git remote add origin <a href="https://your-github-url.github.com/">https://your-github-url.github.com</a><br>$ git add .<br>$ git commit -m&#39;Initial Commit&#39;<br>$ git push origin master</pre><p>We should now have a Github repository that is ready to deploy.</p><h3>Creating our Workflow</h3><p>Github actions, like many CI platforms, operate on what are called workflows. The idea is to list several “jobs” that need completing and the steps in which to follow to complete them. Think of it as a recipe for a cake.</p><p>Our workflow is going to be made up of two jobs one for each stage “build” and “deploy”. To achieve this let’s create a new workflow file in ./.github/workflows/deploy.yml.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe0fb480a0dea2309ee1f6a981e651c0/href">https://medium.com/media/fe0fb480a0dea2309ee1f6a981e651c0/href</a></iframe><p>Above is the full workflow file, but let’s jump through some key parts of this and see how it works.</p><p>The first section on:.. declares what triggers our workflow should respond to. Which our current setup we will run the workflow every time changes are pushed or merged into the master branch.</p><p>The next section under jobs contains the two jobs that we are going to run each is named accordingly build and deploy. Jobs are made up of steps, let’s jump into each job briefly and see which steps make these up.</p><h4>Build Job</h4><p>The first job is to compile all of our react code, this essentially follows what we would normally do with a react application.</p><p>The first step -uses: actions/checkout@v2 as the comment implies pulls our code into the container running the build.</p><p>We then run a custom step, that simply runs our build script, which sits as an npm command in our package.json. Doing so will generate our built assets in a folder called “dist” within the container.</p><p>The final step is to upload these assets known as “artifacts” so that they can be downloaded and used in the deploy job.</p><pre>- name: Upload Artifacts<br>  uses: actions/upload-artifact@v1<br>  with:<br>    name: dist<br>    path: dist</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nVe8MVCibA_drj-MTR804A.png" /></figure><p>Essentially we’re calling the “upload-artefact” action and passing it the name of our artefact and the path at which it can be found. We probably want everything in the dist directory so we just upload that.</p><h4>Deploy Job</h4><p>The final part of our workflow is to upload all of our assets to our s3 bucket. Remember the artefacts we uploaded in the last stage? Well, the first step of this Job is to download them into the new Job container. This is handled by the first step.</p><pre>- name: Download Artifacts<br>  uses: actions/download-artifact@v1<br>  with:<br>    name: dist</pre><p>Finally, we want to sync these assets over to s3, luckily someone has already built a s3 sync action</p><p><a href="https://github.com/jakejarvis/s3-sync-action">GitHub - jakejarvis/s3-sync-action: 🔄 GitHub Action to sync a directory with a remote S3 bucket 🧺</a></p><p>We can just drop that into the final part of our script and let it role. For security reasons we’re using Github secrets to pass in our aws credentials more details on that here: <a href="https://github.com/jakejarvis/s3-sync-action">https://github.com/jakejarvis/s3-sync-action</a></p><pre>- name: &quot;Uploading...&quot;<br>  uses: jakejarvis/s3-sync-action@master<br>  with:<br>    args: --acl public-read --follow-symlinks --delete<br>    env:<br>        AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}<br>        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}<br>        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}<br>        AWS_REGION: &quot;eu-west-1&quot; # optional: defaults to us-east-1<br>        SOURCE_DIR: &quot;dist&quot; # optional: defaults to entire repository</pre><h3>And that’s all.</h3><p>You should now be able to push up / merge into your master branch and watch the build tick away and finally result in your react app hosted on s3.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0b8d1e3eb72" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/building-and-deploying-your-first-react-app-e0b8d1e3eb72">Deploying a React application to Amazon s3 with Github actions.</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Path to gRPC with Node.js]]></title>
            <link>https://tech.holidayextras.com/the-path-to-grpc-with-node-js-e2be9b5d3c5c?source=rss-91a8493b0c2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2be9b5d3c5c</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[grpc]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Tom Vance]]></dc:creator>
            <pubDate>Mon, 08 Apr 2019 09:29:39 GMT</pubDate>
            <atom:updated>2019-04-08T17:26:55.918Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e3Tki2Gc5-wX1IV2gJhjiA.jpeg" /></figure><h3>The Path To gRPC in Node.js</h3><h3>What is gRPC?</h3><p>Anyone who’s working on, with, or has been reading about microservices has probably heard of gRPC in some form or another. In fact, anyone using a library from Google is probably already using it without even knowing.</p><p>gRPC is an open source project aimed to make service communication easy. Pinching the description from the gRPC website:</p><blockquote>gRPC is a modern open source high performance RPC framework that can run in any environment. It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking and authentication. It is also applicable in last mile of distributed computing to connect devices, mobile applications and browsers to backend services. — <a href="https://grpc.io/about/">https://grpc.io/about/</a></blockquote><h3>Using gRPC with Node.js</h3><h4>Define your service</h4><p>Before we start writing our code we need to outline what our services API will look like, defining the functions we wish to expose and the parameters that they will be expecting. With gRPC this is done via a protobuf file. Profobuf is a schema definition language more documentation can be found here:</p><p><a href="https://developers.google.com/protocol-buffers/docs/proto3">Language Guide (proto3) | Protocol Buffers | Google Developers</a></p><p>Let’s define a really simple service called Calculator, that will expose a single function named Add. It will take two numbers and simply return the result of adding these together:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17daeaa7ed6c9c1290debcb7b92e08b2/href">https://medium.com/media/17daeaa7ed6c9c1290debcb7b92e08b2/href</a></iframe><p><strong>Note: </strong>With gRPC we cannot have an input or output type that is a singular value. This is notable on the AddReply message. Normally we would just return the value directly rather than an object of result. The reason for this is extensibility, doing this allows us to add new data points without it being a breaking change.</p><h4>Expose your service</h4><p>Now that our service is defined we need to implement it using Node.js. As with most things in Javascript this starts off by installing a couple of node modules.</p><p>$ npm install grpc @grpc/proto-loader</p><p>Now we need to create our Node.js server, this is actually fairly simple. There is some simple bootstrapping of our gRPC server. But mainly we just need to implement the Add function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/24da0830efae0e996c17677bdd58592f/href">https://medium.com/media/24da0830efae0e996c17677bdd58592f/href</a></iframe><h4>Talk to your service</h4><p>Now that we have our gRPC server running, we need to be able to call the functions that we have exposed. This is where our .proto file comes in to play again.</p><p>Each client that talks to your server needs to have a copy of your proto definitions. This allows the gRPC module to know what shape requests should take. There are a number of ways of sharing these but for now we can just copy and paste them around.</p><p>Creating a gRPC client is relatively simple and isn’t dissimilar from the code for the server:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/411540eb54f9c569e573975604794318/href">https://medium.com/media/411540eb54f9c569e573975604794318/href</a></iframe><h3>And Thats It</h3><p>We now have a very simple gRPC client / server. This can be expanded significantly and there are lots of awesome guides on line and examples available here</p><p><a href="https://grpc.io/">gRPC</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2be9b5d3c5c" width="1" height="1" alt=""><hr><p><a href="https://tech.holidayextras.com/the-path-to-grpc-with-node-js-e2be9b5d3c5c">The Path to gRPC with Node.js</a> was originally published in <a href="https://tech.holidayextras.com/">Holiday Extras Tech Team</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a phrase classifier with Javascript.]]></title>
            <link>https://tech.holidayextras.com/build-a-phrase-classifier-with-javascript-b6d4821de447?source=rss-91a8493b0c2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6d4821de447</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[naturallanguageprocessing]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Tom Vance]]></dc:creator>
            <pubDate>Mon, 31 Dec 2018 15:13:30 GMT</pubDate>
            <atom:updated>2018-12-31T15:49:38.161Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build a simple phrase classifier with Javascript.</h3><h4>Machine learning using Brain.js</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YPCyUqPjBd66Wl6bvBaLOg.jpeg" /></figure><p>Machine learning and AI can be pretty complex subjects to understand, but Brain.js makes things a bit simpler. Let’s have a crack at writing a small program that will tell us if a phrase is written in a positive or a negative way.</p><blockquote><strong>Note</strong>: Full example is available on Github link is at the end of this post.</blockquote><blockquote><strong>Note two: </strong>This is a simplified example, this is by no means the best way to perform sentiment analysis. However, this does explain some of the key concepts involved with data classification.</blockquote><h3>What is Brain.js?</h3><p>Brain.js is an amazing library that exposes simple to use Neural Networks for use in Javascript projects. I highly recommend checking out their documentation on Github and see what you can come up with.</p><p><a href="https://github.com/BrainJS/brain.js">GitHub - BrainJS/brain.js: 🤖 GPU accelerated Neural networks in JavaScript for Browsers and Node.js</a></p><h3>Natural Language Processing.</h3><p>To build something that can identify the following phrase as positive or negative we are going to need some form of Natural Language Processing. For this example, we are going to implement a basic classifier that will allow us to do just that.</p><blockquote>“I love lasagna, it makes me happy with it’s cheesy goodness.”</blockquote><p>There are a number of steps to classifying a phrase like this, we will go through each of these and look at how it could be implemented with Javascript.</p><h3>A training dataset.</h3><p>Before we start writing some code we need to build a base training set. Essentially what we are going to need is a bunch of phrases that we have already classified. The more data we have the more accurate our system will be, however, for something simple we can get away with the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/899a959c2ce3fd7052468830da435200/href">https://medium.com/media/899a959c2ce3fd7052468830da435200/href</a></iframe><h3>Building Our Word Dictionary</h3><p>The first thing we will want to do is build our “word dictionary” essentially this is going to be a unique normalised array of all the words from our training set. Each of these words will be run through a word stemming algorithm:</p><blockquote>A stemmer for English operating on the stem <em>cat</em> should identify such <a href="https://en.wikipedia.org/wiki/String_literal">strings</a> as <em>cats</em>, <em>catlike</em>, and <em>catty</em>. A stemming algorithm might also reduce the words <em>fishing</em>, <em>fished</em>, and <em>fisher </em>to the stem <em>fish</em>. The stem need not be a word, however. In the Porter algorithm, <em>argue</em>, <em>argued</em>, <em>argues</em>, <em>arguing</em>, and <em>argus</em> reduce to the stem <em>argue</em>. — Wikipedia <a href="https://en.wikipedia.org/wiki/Stemming#Examples">https://en.wikipedia.org/wiki/Stemming#Examples</a></blockquote><p>Thankfully some people, much more clever people than myself, (<a href="https://github.com/NaturalNode">NodeNatural</a>) have created a bunch of these for us in their <a href="https://github.com/NaturalNode/natural#stemmers">Natural</a> library.</p><p><a href="https://github.com/NaturalNode/natural">NaturalNode/natural</a></p><p>To do this in Javascript we can write a simple function that takes in our training phrases (see the test data above) and returns back the single dictionary array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4474d4679f6c8be55af0ae8a6dbe11f/href">https://medium.com/media/f4474d4679f6c8be55af0ae8a6dbe11f/href</a></iframe><h3>Encoding our data set.</h3><p>We now have a simplified representation of our training data. What we need to do next is to turn our data into something that is modelable. We do this by creating an encoding function that will convert our phrases into binary strings. Hopefully, all of that sounds simple (If not don’t worry I was confused at this point too).</p><p>The easiest way I found to imagine this step is to create a matrix, we can then plot our data on to this matrix which will result in our binary strings. For example, if we had a smaller training set with the phrases:</p><pre>&quot;Hello World&quot;,<br>&quot;Hello my name is tom&quot;</pre><p>Our resulting matrix would look like this, essentially we plot each token along the top and place a 1 or a 0 under it if the phrase contains it:</p><pre>                      &quot;hello&quot; &quot;world&quot; &quot;my&quot; &quot;name&quot; &quot;is&quot; &quot;tom&quot;<br>&quot;Hello World&quot;            1      1       0     0    0    0<br>&quot;Hello my name is tom&quot;   1      0       1     1    1    1</pre><p>Doing this in Javascript is actually pretty simple now that we have created our dictionary. We can simply loop over each of our training phrases and check if each of the words exists in the dictionary:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/884646db266eb176a561a47e767b203c/href">https://medium.com/media/884646db266eb176a561a47e767b203c/href</a></iframe><p>For example:</p><pre>const dictionary = [&#39;hello&#39;, &#39;world&#39;, &#39;my&#39;, &#39;name&#39;, &#39;is&#39;, &#39;tom&#39;]<br>console.log(encode(&#39;hello tom&#39;))</pre><pre>// [1, 0, 0, 0, 0, 1]</pre><h3>Create and Train a Neural Network.</h3><p>Now we have a way to build our encoded strings we can being to create our Neural Network. This is where we can harness the power of Brain.js, it takes all of these complexities away from us and exposes a simple to use API:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec41877d699990c441d4cbee820a6fec/href">https://medium.com/media/ec41877d699990c441d4cbee820a6fec/href</a></iframe><p>Yup, that’s really all it takes. We have now trained a Neural Network with our training data and it’s now ready to be tested.</p><h3>Testing Our Network.</h3><p>The best way to test this is to take another phrase with a known result for example:</p><pre>Im so happy to have cake // good: 1</pre><p>We can then just run this through the encoding process and then run it through our network:</p><pre>const encoded = encode(&quot;Im so happy to have cake&quot;)<br>console.log(network.run(encoded))<br>// { good: 0.8156641125679016, bad: 0.17976993322372437 }</pre><p>The result is a probability of how confident our Neural Network is on the result.</p><h3>And that&#39;s it!</h3><p>We have a working neural network that is able to identify positive and negative phrases.</p><p>Now, of course, this is a very simplified solution to a difficult problem space. But the idea here is to show how simple Brain.js makes common classification problems. It also demonstrates the encoding process, you can imagine taking other complex data sources, images, videos etc.. running them through an encoding function and following a similar process to classify them correctly.</p><p>I have put the full example on GitHub feel free to explore the code and raise any questions you may have as issues :)</p><p><a href="https://github.com/TomVance/simple_phrase_classifier">TomVance/simple_phrase_classifier</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6d4821de447" width="1" height="1" alt=""><hr><p><a href="https://tech.holidayextras.com/build-a-phrase-classifier-with-javascript-b6d4821de447">Build a phrase classifier with Javascript.</a> was originally published in <a href="https://tech.holidayextras.com/">Holiday Extras Tech Team</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ParcelJS: How simple really is it?]]></title>
            <link>https://tech.holidayextras.com/parceljs-how-simple-really-is-it-679a4feba69d?source=rss-91a8493b0c2b------2</link>
            <guid isPermaLink="false">https://medium.com/p/679a4feba69d</guid>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[bundler]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[parcel-js]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Tom Vance]]></dc:creator>
            <pubDate>Wed, 16 May 2018 22:26:29 GMT</pubDate>
            <atom:updated>2018-06-21T12:29:23.582Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gjhk6qvPM5zAy1iPPS1ttg.png" /></figure><p>ParcelJS promises to be a “Blazing fast, zero configuration web application bundler”.</p><p>I wanted to put this to the test…</p><h3>Getting Going</h3><p>To get started I created a empty directory and followed the setup guide here: <a href="https://parceljs.org/getting_started.html">https://parceljs.org/getting_started.html</a>.</p><p>Now that I had the required CLI tools in place I wanted to see how quickly I could get something up and running. I decided to put a simple react application together.</p><p>This is something I have done plenty of times with webpack, yet it had always taken me half an hour or so to get going from a clean slate.</p><h4>The Seemingly Simple First Step</h4><p>So according to the documentation I could simply create some files and start running things. I started a new node project with yarn init and created my static html file index.html .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2fc42bcd978def9a103afbc77954b584/href">https://medium.com/media/2fc42bcd978def9a103afbc77954b584/href</a></iframe><p>To test that all of this was working correctly I quickly created a simple javascript file called app.js that would console log a message to my terminal:</p><pre>// app.js</pre><pre>console.log(&#39;Hello From Parcel&#39;);</pre><p>I then simply ran the parcel command to get my app running:NODE_ENV=development parcel ./index.html to my amazement things started to happen. I was greeted with a nice message indicating that I could see my application running at <a href="http://localhost:1234/">http://localhost:1234/</a> . Upon visiting this and checking my console, I was pretty happy to see the the message was displayed as expected.</p><h4>Wow.. you got it to say hello?</h4><p>Okay yes, this is a very trivial example so lets press on with the react application and see what happens.</p><p><strong><em>Note: </em></strong><em>Im going to presume from this point onwards that people know how react works. If not there are great guides online.</em></p><p>So the next step was to start creating a react component to render to the page, again I went for a simple change. Rather than logging “Hello From Parcel” to my console I just wanted to get this rendering as text to the DOM.</p><p>I created a simple stateless react component to achieve this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/629e69a01e22c120868086a540b54247/href">https://medium.com/media/629e69a01e22c120868086a540b54247/href</a></iframe><p>I then updated my code in the app.jsfile to render my components to the DOM.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e8f3e0dd14dee8db0b834ffa52637b7/href">https://medium.com/media/3e8f3e0dd14dee8db0b834ffa52637b7/href</a></iframe><p>And with that I simply re ran the command from before:NODE_ENV=development parcel ./index.html and refreshed my browser window and too my amazement boom, there it was printed clear as day.</p><p>So I know all of the above is very simple, but from here it was no different to building out a normal react application. Adding routing, redux etc.. all just works. For me this is a game changer, I was so impressed with how quickly I got up and running, no jumping around babel and webpack config files. One command to rule them all.</p><h3>Extra Snazzy Features</h3><p>So I didn’t touch on these in the main article as I wanted to keep it simple, but Parcel actually ships with so much more than what I’ve mentioned above. I just had to share the joys with you.</p><h4>CSS and LESS Support</h4><p>So I wanted to add some styling, oh great yet another webpack plugin to deal with, oh no on the contrary. Doing this with Parcel was easy as pie. You can literally create a file called styles.less and then import it into your javascript as you need it. For my use case I simply added one line to my app.js file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4eb127ce442d212afb2adf3dd01d2897/href">https://medium.com/media/4eb127ce442d212afb2adf3dd01d2897/href</a></iframe><p>Boom I had styling.</p><h4>Hot Reloading</h4><blockquote>“Im too lazy to refresh my browser each time I make a change so I better install that webpack plugin over here to do it for me”- <strong>Tom Vance 2018</strong></blockquote><p>No longer! Parcel ships with hot reloading out of the box simple add 3 lines of javascript to your main entry point, in my case app.js :</p><pre><em>// Hot Module Replacement</em></pre><pre>if (module.hot) {<br>    module.hot.accept()<br>}</pre><p>Yeh okay this stuff really is simple.</p><h3>Code Splitting</h3><p>Right, this one isn’t as simple as the others have been but with one extra module this stuff becomes a piece of cake.</p><p>Parcel ships with code splitting abilities. However getting into React takes a little more work, I mean come on i’ve just saved you like forty minutes in this article so far.</p><p>The best way that i’ve found to harness code splitting into React and dealing with all the async hackz is to use this great module:</p><p><a href="https://www.npmjs.com/package/react-async-component">react-async-component</a></p><p>I decided to write my own little HOC around this as it made my life easier through out the project. Below is this HOC and an example of it’s usage:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/220f5095d7624d83725a87b97aa28145/href">https://medium.com/media/220f5095d7624d83725a87b97aa28145/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ead85c487ca1de420bfd85c3cceba115/href">https://medium.com/media/ead85c487ca1de420bfd85c3cceba115/href</a></iframe><p>Now the above does introduce react router but for good reason, the best way I could test out the code splitting was to ensure they loaded on different routes. I may end up writing more about how code splitting works in Parcel, but for now you’re stuck with this.</p><p>By simply opening the network tab in chrome dev tools and switching from the / route to the /#/about route you can see the two chunks loading in.</p><h3>In Conclusion</h3><p>Simply this is freaking awesome, everything just works. You should just use this and be done with it.</p><p>In all seriousness though, with how quickly everything changes in the front end world tools like this make all the difference. It saves time and effort and really lets you get down to the important parts of building your applications.</p><p>Mad props to the guys at <a href="https://parceljs.org/">https://parceljs.org/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=679a4feba69d" width="1" height="1" alt=""><hr><p><a href="https://tech.holidayextras.com/parceljs-how-simple-really-is-it-679a4feba69d">ParcelJS: How simple really is it?</a> was originally published in <a href="https://tech.holidayextras.com/">Holiday Extras Tech Team</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>