<?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 Frank Orellana on Medium]]></title>
        <description><![CDATA[Stories by Frank Orellana on Medium]]></description>
        <link>https://medium.com/@frankorellana?source=rss-3929a0bbd46------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*sqfny0fiMrRJPSkB.</url>
            <title>Stories by Frank Orellana on Medium</title>
            <link>https://medium.com/@frankorellana?source=rss-3929a0bbd46------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 18:11:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@frankorellana/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[Configuring Sonarqube in a Vite project, with Vue, Typescript and Vitest]]></title>
            <link>https://frankorellana.medium.com/configuring-sonarqube-in-a-vite-project-with-vue-typescript-and-vitest-48a302972c24?source=rss-3929a0bbd46------2</link>
            <guid isPermaLink="false">https://medium.com/p/48a302972c24</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[vitejs]]></category>
            <dc:creator><![CDATA[Frank Orellana]]></dc:creator>
            <pubDate>Thu, 17 Mar 2022 03:49:36 GMT</pubDate>
            <atom:updated>2022-04-05T03:37:52.678Z</atom:updated>
            <content:encoded><![CDATA[<p>This will allow us to configure Sonarqube to check code quality and test coverage for our vite project, you can check the full source code in the <a href="https://github.com/frank-orellana/vite-vitest-sonarqube">github repo</a></p><h3>Create a Vite project and install Vitest</h3><p>Create a new vite project if you don’t have one, I’m using a vue-ts template, execute the following commands and follow the console instructions:</p><pre>pnpm create vite</pre><pre>pnpm i vitest -D</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*LDNuOSPEZ7FRjdJXGrgP8g.png" /></figure><h4>Add commands to your package.json file</h4><p>Add this commands in the scripts section:</p><pre>&quot;test&quot;: &quot;vitest&quot;,<br>&quot;coverage&quot;: &quot;vitest run --coverage&quot;</pre><h4>Write your first test</h4><p>Create a new test file, you can name it whatever you want but it needs to have a .test.ts or .test.js extension:</p><pre>// src/test/App.test.ts<br>import App from &#39;../App.vue&#39;<br>import { test, expect } from &#39;vitest&#39;;</pre><pre>test(&#39;first test&#39;, () =&gt; {<br>  expect(App).toBeTruthy()<br>})</pre><h4>Run the tests</h4><p>Run the tests with the following command, you should see an output similar to the image:</p><pre>pnpm test</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*UmemVbD3_RYDXXXTNHjKrw.png" /></figure><h4>Run the coverage</h4><p>Run the coverage command, the first time it might ask you to install some additional dependencies like c8 , accept them and run it again:</p><pre>pnpm coverage<br># yes when asked to install c8</pre><p>You should see an output like this in the console:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*uSc__RrsiBsWUyvY3Qp0dg.png" /></figure><h4>Add the coverage folder to .gitignore (optional)</h4><p>You might want to add the coverage and .scannerwork folder to the .gitignore file to avoid unnecessary changes:</p><pre>// .gitignore<br>coverage<br>.scannerwork</pre><p>With this we now have a vite project, with vitest installed and configured to run unit tests and show the coverage, now onto sonarqube</p><h3>Configure project in Sonarqube</h3><p>I assume you have Sonarqube already installed or have access to a Sonarqube server. If you don’t, go to <a href="https://docs.sonarqube.org/latest/setup/get-started-2-minutes/">this website</a> and install it, I used the docker method and had it running within minutes</p><h4>Create project</h4><p>Login to your Sonarqube server (usually in http://localhost:9000, user: admin, password: admin), and create a new project, name it whatever you want, and remember the Project key:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*k2xmz0SAnVsHZ-q3gXdMHw.png" /></figure><p>Follow all the steps in the wizard, select local and manual when asked unless you want something else.</p><h4>Generate a token</h4><p>When you get to the <strong>Analyze your project</strong> step, generate a new token, and<strong> be sure to copy the generated string</strong>, i.e. 301c155db793aafe16df33162b0f…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*Al9zszx9RGptOL_V_ZiIuA.png" /></figure><p>you can ignore the following step</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*DecnIRTCjK_xyawkUhj1UA.png" /></figure><h3>Configure Sonarqube in your project</h3><h4>Install sonar-scanner</h4><p>If you don’t have it already, the easiest way is to install it as a dev dependency in your project:</p><pre>pnpm i sonar-scanner -D</pre><h4>Configure vitest</h4><p>We need to tell vitest to generate an lcov.info report, so that sonarqube can read it, add a vitest.config.ts file to the root of your project with this content:</p><pre>/// &lt;reference types=&quot;vitest&quot; /&gt;</pre><pre>import { defineConfig } from &#39;vite&#39;<br>import Vue from &#39;<a href="http://twitter.com/vitejs/plugin-vue">@vitejs/plugin-vue</a>&#39;</pre><pre>export default defineConfig({<br>  plugins: [<br>    Vue(),<br>  ],<br>  test: {<br>    <strong>coverage: {<br>      reporter: [&#39;text&#39;, &#39;lcov&#39;]<br>    }</strong><br>  },<br>})</pre><h4>Run the coverage again</h4><p>You’ll have to run the coverage again, now that we updated the config, you’ll have to run it before executing the reports so you have the latest coverage info</p><pre>pnpm coverage</pre><h4>Configure your sonarqube properties</h4><p>Add a sonar-project.properties file to the root of your project with the following contents, make sure to update it with your project key, and your sonarqube server:</p><pre>sonar.projectKey=<strong>vite-vitest-sonarqube</strong><br>sonar.sources=src/<br>sonar.javascript.lcov.reportPaths=coverage/lcov.info<br>sonar.exclusions=dist/**<br>sonar.coverage.exclusions=**/*.test.*<br>host.url=<a href="http://localhost:9000/"><strong>http://localhost:9000</strong></a></pre><h4>Run the report</h4><p>Now we are finally ready to execute our scan, run this command in the root of your project, replacing &lt;your_token&gt; with the string generated when configuring your project:</p><pre>npx sonar-scanner -Dsonar.login=&lt;your_token&gt;<br>#i.e. npx sonar-scanner -Dsonar.login=301c155db793aafe16df33162b<br># Remember to run the pnpm coverage script before executing this!</pre><p>if you had sonar-scanner globally installed already, you might want to skip the npx part</p><h4>Optional: Add sonar script to package.json</h4><p>Add your token as an environment variable:</p><pre><strong># Linux, mac</strong><br>export SONAR=301c155db793aafe16df33162b</pre><pre><strong># windows</strong><br>setx SONAR 301c155db793aafe16df33162b</pre><p>And then add your coverage and scan command as a script in the package.json:</p><pre><strong># Linux, mac</strong><br>&quot;sonar&quot;: &quot;pnpm coverage &amp;&amp; npx sonar-scanner -Dsonar.login=$SONAR&quot;</pre><pre><strong># windows</strong><br>&quot;sonar&quot;: &quot;pnpm coverage &amp;&amp; npx sonar-scanner -Dsonar.login=%SONAR%&quot;</pre><p>Then you can run <strong>pnpm sonar</strong> and it will automatically run the coverage and update your project in Sonarqube</p><h4>See the report in Sonarqube</h4><p>Go to your Sonarqube server (usually http://localhost:9000) and see the results for your project:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gzy1tD4PTFET2Ow248nIgQ.png" /></figure><p>And that’s it, you can now update your source and run the last command as many times as you want.</p><h3>TL;DR</h3><pre># Create a vite project, add vitest<br>pnpm create vite<br>pnpm i vitest -D</pre><pre># Add scripts to package.json<br>&quot;test&quot;: &quot;vitest&quot;,<br>&quot;coverage&quot;: &quot;vitest run --coverage&quot;,<br>&quot;sonar&quot;: &quot;pnpm coverage &amp;&amp; npx sonar-scanner -Dsonar.login=$SONAR&quot;<br># In windows %SONAR% instead of $SONAR</pre><pre># Create a unit test file:<br>// src/test/App.test.ts<br>import App from &#39;../App.vue&#39;<br>import { test, expect } from &#39;vitest&#39;;</pre><pre>test(&#39;first test&#39;, () =&gt; {<br>  expect(App).toBeTruthy()<br>})</pre><pre># Run the tests and coverage if you want now<br>pnpm test<br>pnpm coverage</pre><pre># Add the coverage folder to .gitignore<br>coverage</pre><pre>// ***********************************************<br>// Configure Sonarqube<br># Create a project in sonarqube, remember the project key and the token</pre><pre># Add a sonar-project.properties file, set your projecKey and url <br>sonar.projectKey=<strong>vite-vitest-sonarqube</strong><br>sonar.sources=src/<br>sonar.javascript.lcov.reportPaths=coverage/lcov.info<br>sonar.exclusions=dist/**<br>sonar.coverage.exclusions=**/*.test.*<br>host.url=<a href="http://localhost:9000/"><strong>http://localhost:9000</strong></a></pre><pre># Install sonar-scanner if not already installed<br>pnpm i sonar-scanner -D</pre><pre># Configure vitest to generate lcov.info files in vitest.config.ts<br>import { defineConfig } from &#39;vite&#39;<br>import Vue from &#39;<a href="http://twitter.com/vitejs/plugin-vue">@vitejs/plugin-vue</a>&#39;</pre><pre>export default defineConfig({<br>  plugins: [<br>    Vue(),<br>  ],<br>  test: {<br>    <strong>coverage: {<br>      reporter: [&#39;text&#39;, &#39;lcov&#39;]<br>    }</strong><br>  },<br>})</pre><pre># Run coverage and the scan, use your generated token<br>pnpm sonar<br># or<br>npx sonar-scanner -Dsonar.login=&lt;your_token&gt;</pre><pre># Go to your Sonarqube server and look at the report!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48a302972c24" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating SSG page with Vue and Vite]]></title>
            <link>https://frankorellana.medium.com/creating-ssg-page-with-vue-and-vite-8478fe2e4ec6?source=rss-3929a0bbd46------2</link>
            <guid isPermaLink="false">https://medium.com/p/8478fe2e4ec6</guid>
            <category><![CDATA[server-side-rendering]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[static-site-generation]]></category>
            <dc:creator><![CDATA[Frank Orellana]]></dc:creator>
            <pubDate>Wed, 16 Feb 2022 03:42:59 GMT</pubDate>
            <atom:updated>2022-03-13T02:48:41.647Z</atom:updated>
            <content:encoded><![CDATA[<p>While SSR has been all the rage lately, SSG is kind of a new term that makes sense a lot more in some cases, specially when working with SPAs and new frameworks for the web like React or Vue</p><h3>TL;DR</h3><p>On your vite app install:</p><pre><strong>npm i -D vite-ssg<em> @vueuse/head</em></strong> <em>vue-router@next</em></pre><p>Update your build command in the package.json</p><pre>{<br>  &quot;scripts&quot;: {<br>    ...<br>    <strong>&quot;build&quot;: &quot;vite-ssg build&quot;</strong></pre><p>Update your src/main.js file:</p><pre>import { ViteSSG } from &#39;vite-ssg/single-page&#39;<br>import App from &#39;./App.vue&#39;</pre><pre>export const createApp = ViteSSG(App)</pre><h3>SSR vs SSG</h3><ul><li><strong>SSR</strong>: Server Side Rendering</li><li><strong>SSG</strong>: Static Site Generator</li></ul><p>The main difference between the two is the time the static content page is generated: <strong>with SSR, every time the browser requests a page, there needs to be a server that will render some static HTML</strong> based on your Vue or react application, and it will fill it with some default content and send it back.</p><p>While <strong>in SSG, you generate the default HTML at build time</strong>, before deploying, also filled with default content. There’s no need for a server like express because you just have plain text HTML, CSS and JavaScript files.</p><p>Both techniques are used primarily to improve SEO, because an SPA will typically have very little HTML at the beginning, with no content, giving search engines very little to understand and to index your site. Some engines will try to execute the JavaScript in your page to see the contents, but you cannot really count on that every time and you won’t have much control over that.</p><p>Also, both techniques should allow the page to function completely independent of the server once loaded. Once that the page is loaded by the browser, all JavaScript should work as with any typical SPA</p><p>With Vite, you can generate a template for a React, Vue and other frameworks and work really fast with it, lets start by creating a Vue app with Vite</p><h3>Creating a regular Vite App</h3><pre>npm create vite # And enter the following options</pre><pre>✔ Project name: … my-first-ssg<br>✔ Select a framework: › vue<br>✔ Select a variant: › vue  # you can also select vue-ts to work with typescript</pre><p>After the creation is completed, follow the console suggestions to go to your new project and install the dependencies</p><pre>cd my-first-ssg<br>npm install<br>npm run dev</pre><p>After doing that, you should have a vue app up and running. If you haven’t tried Vite before, try making some quick edits to the page and see it reload so quickly!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*yRqFPuybAnVE0IQ_xs4JFQ.png" /></figure><h3>Building the SPA</h3><p>Before going to configure Vite for SSG, lets build the application as it is now. to do that, run the following command in your project folder:</p><pre>npm run build</pre><p>After that, you can navigate to the newly created build folder, and look for the index.html file, it should look very similar to this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7uIEqDydtKEOE6goAcBNNw.png" /><figcaption>index.html file generated by the default build</figcaption></figure><p>Also in the browser you can see the source and it should show the same:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*RLF3hMk-6laRVWIEcGo39A.png" /></figure><p>this is what you would expect for an SPA, an HTML with very little code, no content and only some calls to the javascript files that actually do all the magic.</p><h3>Configuring Vite to build an SSG</h3><p>We’ll use the <a href="https://github.com/antfu/vite-ssg">vite-ssg</a> package, created by members of the official vue team to configure vite, this way we only have a few steps to get everything working:</p><p>the steps will be:</p><ol><li>install the vite-ssg library</li><li>update the build command to use vite-ssg instead of vite</li><li>update the main.js file to generate a ssg page (just change a couple of lines)</li></ol><h4>install vite-ssg:</h4><p>Run the following command on your project root:</p><pre><strong>npm i -D vite-ssg<em> @vueuse/head</em></strong> <em>vue-router@next</em></pre><p>if you are not using the vue-router, you can leave that out of the installation, (you might need to add &quot;skipLibCheck&quot;: true to your tsconfig.json if you do that)</p><h4>Update the build command</h4><p>Update your package.json scripts section, replacing the build command so it looks like this:</p><pre>// package.json<br>{<br>  &quot;scripts&quot;: {<br>    ...<br>    <strong>&quot;build&quot;: &quot;vite-ssg build&quot;</strong><br>    ...<br>  }<br>}</pre><h4>Update your src/main.js file</h4><p>Since our app is really simple and we don’t have routing, we can just replace the main.js file for this:</p><pre>import { ViteSSG } from &#39;vite-ssg/single-page&#39;<br>import App from &#39;./App.vue&#39;</pre><pre>export const createApp = ViteSSG(App)</pre><p>this is the before and after:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kQG2B7biG7a8K0AE85b-9g.png" /></figure><p>If you are using routes in your app, you will need to add a few extra options to this file:</p><pre>import { ViteSSG } from &#39;vite-ssg&#39;<br>import App from &#39;./App.vue&#39;<br>export const createApp = ViteSSG(<br>  // the root component<br>  App,<br>  // vue-router options<br>  { routes },<br>  // function to have custom setups<br>  ({ app, router, routes, isClient, initialState }) =&gt; {<br>    // install plugins etc.<br>  }<br>)</pre><p>and that’s it! we can now build the application and see the difference:</p><p>First, lets run the app locally again to see that everything is still working, stop the old server if it was still running and run again:</p><pre>npm run dev</pre><p>you should see all the same, everything, including the source! why? well, because this command only run a local server for development, we don’t need any SSG or SSR for that.</p><h3>Building the app with SSG enabled</h3><p>Now that we have everything setup, let’s run the build command again and take a look at the new index.html file:</p><pre>npm run build</pre><p>now let’s peek into the index.html file generated in the dist folder:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UcFf_hRN91ItdNVBTG7z0Q.png" /></figure><p>That’s a lot more!, pretty ugly but the browser won’t mind. specially important is to see that the content generated has a lot or all the text that will be shown on the first render to the user. This means that any search engine will see that text too!</p><p>and what about running this?, let’s try it! I will vite preview command that we have for free to run the dist/index.html file, you can also upload it to a web server right away:</p><pre>npm run preview</pre><p>When it runs, you can open the url it shows, usually <a href="http://localhost:4173/">http://localhost:4173/</a>. remember this is not the dev build, this command creates a web server pointing to your dist folder!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*0jO5syGYlejIkPUAm5fxkQ.png" /></figure><p>The app seems ok, if you press the button, all the javascript and vue code should execute normally, the difference is when you go to see the page source:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*clw4MmqqSp6-IU-j7X39fQ.png" /></figure><p>this is what the browser will see when it loads the page, also what any search engine will see, so your indexing should get better because now they have something to index!</p><p>That’s it to get started, you can see SSG provides the best of both worlds between a simple SPA and SSR, plus you don’t need to setup an SSR server!! everything is ready to just deploy to your web server.</p><p>However, if your page is a little more complex that our little example, you might have to pay attention to other aspects of it:</p><h3>Considerations of enabling SSG</h3><ul><li>If your page uses browser specific apis on the first rendering, you might have to tweak things a little bit. Just like with SSR, remember you are not running this first rendering on the browser! so you likely won’t have access to the window object, fetch, etc.</li><li>If you use routing be sure to update the main.js file accordingly.</li><li>If you use a global state library like pinia or vuex, and use them for the first rendering, be sure to read <a href="https://github.com/antfu/vite-ssg#initial-state">this</a> in the official documentation to get going</li><li>SSG just like SSR might not be suitable for all sites or for all sections on your page. SSG is ideal for landing pages but not for user profile pages for example</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8478fe2e4ec6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>