<?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>Forem: Erwan Leboucher</title>
    <description>The latest articles on Forem by Erwan Leboucher (@eleboucher).</description>
    <link>https://forem.com/eleboucher</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%2F160054%2F07b7a6ec-73b5-46fa-b71e-4804b49dfec9.jpg</url>
      <title>Forem: Erwan Leboucher</title>
      <link>https://forem.com/eleboucher</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/eleboucher"/>
    <language>en</language>
    <item>
      <title>How to deploy Docusaurus v2 on GitLab Pages</title>
      <dc:creator>Erwan Leboucher</dc:creator>
      <pubDate>Wed, 23 Dec 2020 08:44:33 +0000</pubDate>
      <link>https://forem.com/eleboucher/how-to-deploy-docusaurus-v2-on-gitlab-pages-14e6</link>
      <guid>https://forem.com/eleboucher/how-to-deploy-docusaurus-v2-on-gitlab-pages-14e6</guid>
      <description>&lt;p&gt;At &lt;a href="https://viafintect.com" rel="noopener noreferrer"&gt;viafintech&lt;/a&gt;, we use &lt;a href="https://v2.docusaurus.io/" rel="noopener noreferrer"&gt;docusaurus&lt;/a&gt; for our internal documentation. We also use GitLab to host our code and to test it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.gitlab.com/ee/user/project/pages/" rel="noopener noreferrer"&gt;GitLab pages&lt;/a&gt; is a feature (like Github pages) that allow us to publish a static website from a GitLab repository. You can host plenty of different static site generator like Gatsby, Hugo, Jekyll... &lt;/p&gt;

&lt;p&gt;&lt;a href="https://v2.docusaurus.io/" rel="noopener noreferrer"&gt;Docusaurus&lt;/a&gt; is a documentation site generator created and maintained by Facebook Open Source. Using Markdown, it allowed us to write documentation faster and also to generate clean docs for our &lt;a href="https://github.com/eleboucher/raml2docusaurus" rel="noopener noreferrer"&gt;RAML files&lt;/a&gt; that describe our endpoints.&lt;/p&gt;

&lt;p&gt;To generate a docusaurus project, use the project generator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;npx @docusaurus/init@latest init [name] [template]
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;for my example I will use the classic template, but you can find more details &lt;a href="https://v2.docusaurus.io/docs/installation#scaffold-project-website" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;npx @docusaurus/init@latest init test-gitlab classic
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you should have the project properly generated in the test-gitlab/ folder.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to setup the gitlab ci
&lt;/h2&gt;

&lt;p&gt;Once you messed up with the docs and you are ready to deploy it. &lt;br&gt;
Create a &lt;code&gt;.gitlab-ci.yml&lt;/code&gt; file that will allow us to create an artifact containing the static resources to allow GitLab pages to render your website.&lt;/p&gt;

&lt;p&gt;The content of the &lt;code&gt;.gitlab-ci.yml&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;node:latest&lt;/span&gt;

&lt;span class="c1"&gt;# allow caching for faster deployment&lt;/span&gt;
&lt;span class="na"&gt;cache&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;node_modules/&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;public/&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;.cache/&lt;/span&gt;

&lt;span class="na"&gt;pages&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;stage&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;deploy&lt;/span&gt;
  &lt;span class="na"&gt;script&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;yarn install&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;yarn build:gitlab&lt;/span&gt;
  &lt;span class="na"&gt;artifacts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;public&lt;/span&gt;
  &lt;span class="na"&gt;only&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;master&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And add this script to the &lt;code&gt;package.json&lt;/code&gt; to allow docusaurus to build the file into the &lt;code&gt;public/&lt;/code&gt; folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"build:gitlab"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"docusaurus build --out-dir public"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to access it
&lt;/h2&gt;

&lt;p&gt;Now you are set to deploy your website, push your newly added stuff and your documentation site should be available. Go on GitLab &amp;gt; Settings &amp;gt; Pages and you will be able to see the link of your page, For me: &lt;a href="https://eleboucher.gitlab.io/test-docs/" rel="noopener noreferrer"&gt;https://eleboucher.gitlab.io/test-docs/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F146uixovoaxone30846t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F146uixovoaxone30846t.png" alt="Setting &amp;gt; pages"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: &lt;br&gt;
Make sure you set up correct the &lt;code&gt;baseURL&lt;/code&gt; in &lt;code&gt;docusaurus.config.js&lt;/code&gt; in case your link is not the root path.&lt;/p&gt;

&lt;p&gt;If you have any questions, feel free to leave a comment!&lt;/p&gt;

&lt;p&gt;Find me on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://twitter.com/elebouch" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/eleboucher" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;p&gt;We are hiring! =&amp;gt; &lt;a href="https://www.viafintech.com/op_software-engineer/" rel="noopener noreferrer"&gt;https://www.viafintech.com/op_software-engineer/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gitlab</category>
      <category>javascript</category>
      <category>react</category>
      <category>documentation</category>
    </item>
  </channel>
</rss>
