<?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: Peter Babič</title>
    <description>The latest articles on DEV Community by Peter Babič (@peterbabic).</description>
    <link>https://dev.to/peterbabic</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%2F165137%2Fe0a5ad40-53da-4a74-90f3-919a06513075.png</url>
      <title>DEV Community: Peter Babič</title>
      <link>https://dev.to/peterbabic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/peterbabic"/>
    <language>en</language>
    <item>
      <title>How to examine the options of a generated boilerplate?</title>
      <dc:creator>Peter Babič</dc:creator>
      <pubDate>Wed, 08 May 2019 21:41:58 +0000</pubDate>
      <link>https://dev.to/peterbabic/how-to-examine-the-options-of-a-generated-boilerplate-5648</link>
      <guid>https://dev.to/peterbabic/how-to-examine-the-options-of-a-generated-boilerplate-5648</guid>
      <description>&lt;p&gt;This article is a mix of multiple domains, mainly Nuxt project scaffolding and m the struggles I went through along with some shell scripting, when this whole trip got me diving deeper. If you are interested in any of this, you are welcome to continue reading.&lt;/p&gt;

&lt;h1&gt;
  
  
  Nuxt project generation
&lt;/h1&gt;

&lt;p&gt;&lt;span&gt;&lt;em&gt;Nuxt.js is a framework for creating Vue.js applications, you can choose between Universal, Static Generated or Single Page application.&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;Following the instructions on their &lt;a href="https://nuxtjs.org/guide/installation#using-code-create-nuxt-app-code-"&gt;installation page&lt;/a&gt; using the &lt;code&gt;create-nuxt-app&lt;/code&gt; scaffolding tool, the first step there is to &lt;em&gt;Choose between integrated server-side frameworks&lt;/em&gt; and currently in Nuxt version &lt;code&gt;2.6.3&lt;/code&gt; you can choose one of the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;None (Nuxt default server)&lt;/li&gt;
&lt;li&gt;Express&lt;/li&gt;
&lt;li&gt;Koa&lt;/li&gt;
&lt;li&gt;Hapi&lt;/li&gt;
&lt;li&gt;Feathers&lt;/li&gt;
&lt;li&gt;Micro&lt;/li&gt;
&lt;li&gt;Adonis (WIP)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are a regular Node user like me, chances are that you have used Express before. There may even be "Hello World!" examples utilizing it as a quickstart guide for Node scattered across the internet, so without much thinking, choosing Express seems like an obvious choice. &lt;/p&gt;

&lt;p&gt;The rest of the installation offers multiple awesome options to get you going. I was really pleased to see &lt;a href="https://buefy.org/"&gt;Buefy&lt;/a&gt; and &lt;a href="https://jestjs.io/"&gt;Jest&lt;/a&gt; in the list. Hopefully you can find most of your favorite choices there as well.&lt;/p&gt;

&lt;p&gt;When the project is generated, you can start building. You write your first Vue component and want to get the data into it. The Axios module is basically the way to go, Nuxt adds some functionality on top of it. You can read more in it's &lt;a href="https://axios.nuxtjs.org/"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Obtaining the data
&lt;/h1&gt;

&lt;p&gt;But where do Axios get data from? Of course, from the integrated server-side framework chosen right in the first step! We have chosen Express, it has to be able to serve data for our simple app easily. No problem - there is a documented way: to use the &lt;a href="https://nuxtjs.org/api/configuration-servermiddleware/"&gt;serverMiddleware&lt;/a&gt; property.&lt;/p&gt;

&lt;p&gt;Unfortunately, it is not all that perfect. There is an open &lt;a href="https://github.com/nuxt/nuxt.js/issues/4301"&gt;issue&lt;/a&gt; with the two related closed issues. Long story short, you can use the &lt;code&gt;serverMiddleware&lt;/code&gt; to serve the data with the framework of choice (one from the step 1 of the Nuxt installation), but the development still needs o lot of server restarting which is painful. You are basically required to have two separate parts - the server and the Nuxt project. Of course, when you work with micro-services, this is expected, but for simplest projects, I would not recommend having the data served directly from the Nuxt application itself yet (although if you follow the issue, you can see it is work in progress).&lt;/p&gt;

&lt;p&gt;Choosing Express won't exactly help us with the development of the server. It is not because of the problem with the Express itself - it is because of the unresolved issue with HMR (Hot Module Replacement) and cache. This makes choosing all the other (koa, hapi, etc.) equally unhelpful. There is but one not self-explanatory choice in the list: the first one. &lt;/p&gt;

&lt;h1&gt;
  
  
  Nuxt default server
&lt;/h1&gt;

&lt;p&gt;What does &lt;code&gt;None (Nuxt default server)&lt;/code&gt; exactly mean? I could not find much details about this choice anywhere - maybe I need to improve my searching skills. However, I decided to dust off my shell scripting skills instead.&lt;/p&gt;

&lt;p&gt;By generating two identical Nuxt projects, one named &lt;code&gt;default-server&lt;/code&gt; and one &lt;code&gt;express-server&lt;/code&gt;, choosing the specified server-side framework option as the only difference. Ready to compare the projects to learn more I fired off the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; diff &lt;span class="nt"&gt;-r&lt;/span&gt; default-server express-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you think ahead, you can understand why it is not such a good idea. My screen got instantly filled with useless data. So I learned how to exclude something from the comparison and went further:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; diff &lt;span class="nt"&gt;-x&lt;/span&gt; node_modules &lt;span class="nt"&gt;-r&lt;/span&gt; default-server express-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was much helpful but it still contained a lot of irrelevant data. I have applied more exclusions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; diff &lt;span class="nt"&gt;-x&lt;/span&gt; node_modules &lt;span class="nt"&gt;-x&lt;/span&gt; package-lock.json &lt;span class="nt"&gt;-x&lt;/span&gt; .nuxt &lt;span class="nt"&gt;-x&lt;/span&gt; README.md &lt;span class="nt"&gt;-r&lt;/span&gt; default-server express-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Really helpful but there is one thing that can be improved:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; diff &lt;span class="nt"&gt;-x&lt;/span&gt; node_modules &lt;span class="nt"&gt;-x&lt;/span&gt; package-lock.json &lt;span class="nt"&gt;-x&lt;/span&gt; .nuxt &lt;span class="nt"&gt;-x&lt;/span&gt; README.md &lt;span class="nt"&gt;-r&lt;/span&gt; default-server express-server 
&lt;span class="nt"&gt;--color&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Perfect.&lt;/p&gt;

&lt;p&gt;The results however are far more minor than I would have thought. The only difference worth mentioning is how the server is started and the presence of the single file in &lt;code&gt;express-server/server/index.js&lt;/code&gt;. See for yourself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;nuxt.config.js
1c1
&lt;/span&gt;&lt;span class="gd"&gt;- import pkg from './package'
--------
&lt;/span&gt;&lt;span class="gi"&gt;+ const pkg = require('./package')
&lt;/span&gt;&lt;span class="p"&gt;3c3,4
&lt;/span&gt;&lt;span class="gd"&gt;- export default {
--------
&lt;/span&gt;&lt;span class="gi"&gt;+ module.exports = {
&lt;/span&gt;
package.json
&lt;span class="p"&gt;2c2
&lt;/span&gt;&lt;span class="gd"&gt;-   "name": "default-server",
--------
&lt;/span&gt;&lt;span class="gi"&gt;+   "name": "express-server",
&lt;/span&gt;&lt;span class="p"&gt;8c8
&lt;/span&gt;&lt;span class="gd"&gt;-     "dev": "nuxt",
--------
&lt;/span&gt;&lt;span class="gi"&gt;+     "dev": "cross-env NODE_ENV=development nodemon server/index.js --watch server",
&lt;/span&gt;&lt;span class="p"&gt;10c10
&lt;/span&gt;&lt;span class="gd"&gt;-     "start": "nuxt start",
--------
&lt;/span&gt;&lt;span class="gi"&gt;+     "start": "cross-env NODE_ENV=production node server/index.js",
&lt;/span&gt;&lt;span class="p"&gt;15c15,16
&lt;/span&gt;&lt;span class="gd"&gt;-     "nuxt": "^2.4.0"
--------
&lt;/span&gt;&lt;span class="gi"&gt;+     "nuxt": "^2.4.0",
+     "express": "^4.16.4"
&lt;/span&gt;
pages/index.vue
&lt;span class="p"&gt;6c6
&lt;/span&gt;&lt;span class="gd"&gt;-         default-server
--------
&lt;/span&gt;&lt;span class="gi"&gt;+         express-server
&lt;/span&gt;
Only in express-server: server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Digging deeper is unfortunately outside the scope of today's article.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;The Nuxt scaffolding tool let's you choose integrated server side framework. It is possible to use it to serve not just the project (bundled JS, CSS and HTML) but the actual data that will hydrate the skeleton as well. However, it is fairly impractical, as it requires constant server restarts to apply even the slightest change, but this might change in the future.&lt;/p&gt;

&lt;p&gt;Choosing no server-side framework using the option &lt;code&gt;Nuxt default server&lt;/code&gt; for the simplest projects looks like better choice over Express due to one less dependency. You probably won't leverage the Express (or any other server-side framework for that matter) much anyway.&lt;/p&gt;

&lt;p&gt;You can see the full difference of the two scaffolded projects in this &lt;a href="https://gist.github.com/peterbabic/7340cdaed731101d8b809c28ace84329"&gt;Gist&lt;/a&gt;. I feel like I am missing something hugely obvious, so please help me point out the important bits. Cheers!&lt;/p&gt;

</description>
      <category>diff</category>
      <category>nuxt</category>
      <category>vue</category>
      <category>express</category>
    </item>
  </channel>
</rss>
