<?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: Paula Mallol</title>
    <description>The latest articles on Forem by Paula Mallol (@pmallol).</description>
    <link>https://forem.com/pmallol</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%2F30802%2F7b2e6e8b-633a-405b-856f-24cb1856e0d8.png</url>
      <title>Forem: Paula Mallol</title>
      <link>https://forem.com/pmallol</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/pmallol"/>
    <language>en</language>
    <item>
      <title>Deploy Middleman with GitHub Actions</title>
      <dc:creator>Paula Mallol</dc:creator>
      <pubDate>Fri, 07 Aug 2020 21:44:03 +0000</pubDate>
      <link>https://forem.com/pmallol/deploy-middleman-with-github-actions-fen</link>
      <guid>https://forem.com/pmallol/deploy-middleman-with-github-actions-fen</guid>
      <description>&lt;p&gt;This is the final step to get the app live using &lt;a href="https://pages.github.com/"&gt;Github Pages&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;Thanks for sticking with me until the end of this series :) .&lt;/p&gt;

&lt;p&gt;Read about how to set up Middleman, either locally or inside a Docker container, in the previous blog posts.&lt;/p&gt;

&lt;p&gt;Setting up &lt;a href="https://github.com/features/actions"&gt;GitHub Actions&lt;/a&gt; is really easy and it just requires you to create a path named &lt;code&gt;./github/workflows&lt;/code&gt; in your repository root directory, inside which all workflow configuration files will be. &lt;/p&gt;

&lt;p&gt;I’ll show you how to achieve making continuous deployments of a dockerized Middleman app to GitHub Pages in just a few steps, but know that you can also configure it to make deployments to AWS or any other server you’d prefer. &lt;/p&gt;

&lt;p&gt;You can find all sorts of predefined actions in &lt;a href="https://github.com/marketplace?type=actions"&gt;GitHub’s marketplace&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In this case, because we are using GitHub Pages, make sure to push your repository to GitHub, make it public, and create a &lt;a href="https://docs.github.com/en/github/working-with-github-pages/creating-a-github-pages-site#creating-a-repository-for-your-site"&gt;&lt;code&gt;‘gh-pages’&lt;/code&gt; branch&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Open your repository’s settings and you should see GitHub Pages was automatically enabled after the new gh-pages branch was created and pushed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eI-F1Wa5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/pmallol/middleman-webpack-demo/master/screenshots/screenshot-3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eI-F1Wa5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/pmallol/middleman-webpack-demo/master/screenshots/screenshot-3.jpg" alt="Screenshot of a GitHub's repository configuration page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Awesome! Thanks GitHub.&lt;/p&gt;

&lt;p&gt;Now create a &lt;code&gt;deploy.yaml&lt;/code&gt; file inside the &lt;code&gt;.github/workflows&lt;/code&gt; directory with the following content: &lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Commit this change inside the &lt;code&gt;‘master’&lt;/code&gt; branch and push it to your repository. This will generate the &lt;code&gt;GITHUB_TOKEN&lt;/code&gt; needed by the &lt;a href="https://github.com/marketplace/actions/github-pages-action"&gt;GitHub Pages action&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hAylpJMR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/pmallol/middleman-webpack-demo/master/screenshots/screenshot-4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hAylpJMR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/pmallol/middleman-webpack-demo/master/screenshots/screenshot-4.jpg" alt="Screenshot of a GitHub's repository Action tab log page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This first workflow run will probably fail, that’s ok!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You can monitor workflows navigating to the &lt;a href="https://github.com/pmallol/middleman-webpack-demo/actions"&gt;‘Actions’ tab&lt;/a&gt; of your GitHub repository.&lt;/p&gt;

&lt;p&gt;Now it’s the perfect time to modify &lt;a href="https://middlemanapp.com/advanced/configuration/#environment-specific-settings"&gt;Middleman’s build configuration&lt;/a&gt;. When Middleman is built with the command &lt;code&gt;$ bundle exec middleman build&lt;/code&gt;, a new build folder is created. The asset files previously located inside the &lt;code&gt;.tmp/dist&lt;/code&gt; folder will be bundled and moved inside the &lt;code&gt;./build&lt;/code&gt; folder in the process.&lt;/p&gt;

&lt;p&gt;Also, because of the way &lt;a href="https://github.blog/2016-12-05-relative-links-for-github-pages/"&gt;relative links are generated in GitHub Pages&lt;/a&gt;, we will need to set a &lt;code&gt;http_prefix&lt;/code&gt; with the name of the repository so that it is added as a prefix to all links in the application.&lt;/p&gt;

&lt;p&gt;Let’s edit the &lt;code&gt;config.rb&lt;/code&gt; file and add a build environment configuration to ensure relative links and paths for &lt;code&gt;.css&lt;/code&gt; and &lt;code&gt;.js&lt;/code&gt; files are set properly:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Commit and then push the changes to &lt;code&gt;master&lt;/code&gt;. This time, the GitHub Actions workflow shouldn’t take as long as the first one because we’ve configured the gems and packages to be &lt;a href="https://docs.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows"&gt;cached&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If your workflow ran successfully, open up your GitHub Page and see what it looks like. It will most likely be located at &lt;code&gt;https://your-gh-username.github.io/your-gh-repo&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Check out the demo: &lt;a href="https://pmallol.github.io/middleman-webpack-demo/"&gt;https://pmallol.github.io/middleman-webpack-demo/&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;If you inspect the site, you should see assets are properly linked, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;head&amp;gt;
   ...
   &amp;lt;link href="/middleman-webpack-demo/style.css" rel="stylesheet"&amp;gt;
   &amp;lt;script src="/middleman-webpack-demo/site.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vVh1NS0g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/pmallol/middleman-webpack-demo/master/screenshots/screenshot-5.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vVh1NS0g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/pmallol/middleman-webpack-demo/master/screenshots/screenshot-5.jpg" alt="Screenshot of Middleman app in GitHub Pages with dev tools open inspecting the head tag of the HTML"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Final touches
&lt;/h2&gt;

&lt;p&gt;Alright, so we now have a really nice app with continuous deployment.&lt;/p&gt;

&lt;p&gt;What’s missing, I believe, is adding a bit of content. As a final step we’re going to add an About page and link it from the Home page.&lt;/p&gt;

&lt;p&gt;When using Middleman, all new content should be located inside the &lt;code&gt;/source&lt;/code&gt; folder. You can read more about how Middleman manages its directory structure in their &lt;a href="https://middlemanapp.com/basics/directory-structure/"&gt;docs&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;So, create an &lt;code&gt;/about&lt;/code&gt; folder inside &lt;code&gt;./source&lt;/code&gt; and inside this &lt;code&gt;/about&lt;/code&gt; folder, create a file named &lt;code&gt;index.html.erb&lt;/code&gt;. This will be our new About page.&lt;/p&gt;

&lt;p&gt;Add some kind of content and a link to the Home page:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;And next, as the last step, let’s make this About page accessible from the Home page. Open up the Home page file located inside the &lt;code&gt;./source&lt;/code&gt; directory also named &lt;code&gt;index.html.erb&lt;/code&gt;, and add a link to the About page at the very bottom:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;And, that’s it!&lt;/p&gt;

&lt;p&gt;We should see the new About page working properly either locally and on the GitHub Page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_-zqy9l3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/pmallol/middleman-webpack-demo/master/screenshots/screenshot-6.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_-zqy9l3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/pmallol/middleman-webpack-demo/master/screenshots/screenshot-6.jpg" alt="Screenshot of an About page of a Middleman app in GitHub Pages"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope these series were useful and please don’t hesitate to drop me a line if you have any questions or comments.&lt;/p&gt;

&lt;h3&gt;
  
  
  Special thanks
&lt;/h3&gt;

&lt;p&gt;Huge thanks to &lt;a href="https://github.com/fnbellomo"&gt;@fnbellomo&lt;/a&gt; who helped me figure out a lot of things throughout the process of making this demo!&lt;/p&gt;

</description>
      <category>middleman</category>
      <category>github</category>
      <category>actions</category>
      <category>deploy</category>
    </item>
    <item>
      <title>Dockerize Middleman</title>
      <dc:creator>Paula Mallol</dc:creator>
      <pubDate>Fri, 07 Aug 2020 21:20:56 +0000</pubDate>
      <link>https://forem.com/pmallol/dockerize-middleman-2mj8</link>
      <guid>https://forem.com/pmallol/dockerize-middleman-2mj8</guid>
      <description>&lt;p&gt;Welcome to part 2 of the “Add Webpack, dockerize and deploy your Middleman app to Github Pages” series!&lt;/p&gt;

&lt;p&gt;In the &lt;a href="https://dev.to/pmallol/add-webpack-to-a-middleman-app-3npb"&gt;last post&lt;/a&gt; we built an empty Middleman application locally and added Webpack as the external pipeline. Now it’s time to set up the same app but inside a Docker container to get everything ready for deployment.&lt;/p&gt;

&lt;p&gt;Head over to the previous post to learn how to set up Webpack to your Middleman app or skip this all together and learn how to deploy your Middleman app to GitHub Pages using GitHub Actions, in part 3.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up Docker
&lt;/h2&gt;

&lt;p&gt;If you haven’t already, &lt;a href="https://www.docker.com/get-started"&gt;download Docker&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Create a new file named &lt;code&gt;Dockerfile&lt;/code&gt; in your repository root directory where your &lt;a href="https://middlemanapp.com/basics/install/"&gt;Middleman app already exists&lt;/a&gt;. We’re going to be using a &lt;strong&gt;Ruby 2.6.3&lt;/strong&gt; image and install Node.js in it. &lt;/p&gt;

&lt;p&gt;Open the &lt;code&gt;Dockerfile&lt;/code&gt; file and paste the following configuration for our Docker image:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now create another file in the same root directory with the name &lt;code&gt;docker-compose.yml&lt;/code&gt;, open it and paste these lines:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;We’ll be using port &lt;code&gt;1234&lt;/code&gt; for LiveReload later.&lt;/p&gt;

&lt;p&gt;To get the app up and running using Docker:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run &lt;code&gt;$ docker-compose build&lt;/code&gt; to build the Docker image first.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;$ docker-compose up&lt;/code&gt; to start the container and get the environment ready.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the last command fails, make sure you don’t have the application running locally in a previous terminal session.&lt;/p&gt;

&lt;p&gt;Your app should still be available at &lt;a href="http://localhost:4567/"&gt;http://localhost:4567/&lt;/a&gt;, but now running inside a Docker container!&lt;/p&gt;

&lt;p&gt;You can stop the running container pressing &lt;code&gt;CTRL + C&lt;/code&gt; inside the terminal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding LiveReload
&lt;/h2&gt;

&lt;p&gt;Let’s improve the app by making sure we don’t have to refresh the browser every time we want to see new changes. In order to achieve that we’re going to add &lt;a href="https://middlemanapp.com/basics/development-cycle/#livereload"&gt;LiveReload&lt;/a&gt;. LiveReload will automatically refresh the browser whenever files in the repository are modified.&lt;/p&gt;

&lt;p&gt;With the Docker container stopped, add  this line to the Gemfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem 'middleman-livereload', '~&amp;gt; 3.4.3'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Run &lt;code&gt;$ bundle install&lt;/code&gt; to install the LiveReload gem.&lt;/p&gt;

&lt;p&gt;Open your &lt;code&gt;config.rb&lt;/code&gt; file and add the following lines of code under the “&lt;code&gt;# Activate and configure extensions&lt;/code&gt;” section, to activate LiveReload in our application:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Because we modified the &lt;code&gt;Gemfile&lt;/code&gt;, we need to build the docker image again:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run &lt;code&gt;$ docker-compose build&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;Start the web container again running: &lt;code&gt;$ docker-compose up&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Try modifying any css property to quickly see LiveReload in action. The browser should refresh the preview automatically.&lt;/p&gt;

&lt;p&gt;Great! &lt;/p&gt;

&lt;p&gt;Now the application is all set and ready to be deployed.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>middleman</category>
      <category>webpack</category>
      <category>githubpages</category>
    </item>
    <item>
      <title>Add Webpack to Middleman</title>
      <dc:creator>Paula Mallol</dc:creator>
      <pubDate>Fri, 07 Aug 2020 14:56:35 +0000</pubDate>
      <link>https://forem.com/pmallol/add-webpack-to-a-middleman-app-3npb</link>
      <guid>https://forem.com/pmallol/add-webpack-to-a-middleman-app-3npb</guid>
      <description>&lt;p&gt;This blogpost will be the starting point for a 3 part series on how to deploy a Middleman app using Webpack to GitHub Pages in simple steps.&lt;/p&gt;

&lt;p&gt;We’ll go through:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The creation of an empty Middleman application using Webpack as an &lt;a href="https://middlemanapp.com/advanced/external-pipeline/"&gt;external pipeline&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dockerizing your Middleman application (plus, adding LiveReload to refresh the browser after new changes)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finish it off by configuring deployment to GitHub Pages using GitHub Actions&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can check out the &lt;a href="https://pmallol.github.io/middleman-webpack-demo"&gt;demo&lt;/a&gt; to see how it ends up looking on my own personal GitHub page, or you can skip this whole blogpost and head over to the &lt;a href="https://github.com/pmallol/middleman-webpack-demo"&gt;repository&lt;/a&gt; to check out all the files and configurations.&lt;/p&gt;

&lt;p&gt;The final result will be an empty Middleman app with an About page, it will have Webpack integrated and all relative links working properly according to &lt;a href="https://github.blog/2016-12-05-relative-links-for-github-pages/"&gt;Github Pages relative paths&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Also, head over to this dev.to article by &lt;a href="https://dev.to/lxxxvi"&gt;Mario&lt;/a&gt; if you are looking to add TailwindCSS! &lt;a href="https://dev.to/lxxxvi/middleman-tailwindcss-webpack-ap3"&gt;Middleman + TailwindCSS + Webpack&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up the environment locally
&lt;/h2&gt;

&lt;p&gt;Middleman is really simple to set up locally and it is distributed with the RubyGems package manager so you will need to install both the Ruby language and RubyGems first.&lt;/p&gt;

&lt;p&gt;We will be working with &lt;strong&gt;Ruby’s 2.6.3 version&lt;/strong&gt;, make sure to upgrade yours if necessary. You can check which Ruby version you have installed by running $ ruby -v and easily upgrade it with &lt;a href="https://rvm.io/"&gt;rvm&lt;/a&gt;, a Ruby version manager:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run &lt;code&gt;$ rvm list&lt;/code&gt; to list the available Ruby versions installed in your rvm&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;$ rvm install 2.6.3&lt;/code&gt; to install the desired version&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;$ rvm use 2.6.3&lt;/code&gt; to use a specific Ruby version&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, lets update the Ruby Gems:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ gem update --system
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If you are already good to go, follow this &lt;a href="https://middlemanapp.com/basics/install/"&gt;get started guide&lt;/a&gt; to install Middleman or just try running the following command in a new terminal session:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo gem install middleman
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Create a new Middleman application by running middleman’s built in command &lt;code&gt;$ middleman init&lt;/code&gt;. You can either execute it inside your project’s folder or include the desired project name in the same command and let Middleman do everything for you:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ middleman init your_new_project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Move inside your project’s folder to check how it all looks and let’s start a Middleman server for our first live preview:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd your_new_project

$ bundle exec middleman server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Open a browser at &lt;a href="http://localhost:4567/"&gt;http://localhost:4567/&lt;/a&gt;. You should be able to see your new Middleman app!&lt;/p&gt;

&lt;p&gt;Stop the preview server by pressing &lt;code&gt;CTRL + C&lt;/code&gt; in the terminal session.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XxbzeMxc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/pmallol/middleman-webpack-demo/master/screenshots/screenshot-7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XxbzeMxc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/pmallol/middleman-webpack-demo/master/screenshots/screenshot-7.jpg" alt="Screenshot of Middleman app running in a browser at http://localhost:4567/"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Adding Webpack
&lt;/h2&gt;

&lt;p&gt;We’re now ready to install and configure Webpack in the project. Start with initiating npm, and then installing Webpack:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm init -y

$ npm install webpack webpack-cli --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Open the &lt;code&gt;package.json&lt;/code&gt; file created in the repository root and edit its content to add Webpack’s scripts:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Also, we’re going to need some extra packages to handle how stylesheets are bundled. To make it easier for you, just copy and paste this entire line in your terminal to install them all at once:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ npm install --save-dev mini-css-extract-plugin sass-loader css-loader node-sass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Don’t forget to add &lt;code&gt;node_modules&lt;/code&gt; inside the &lt;code&gt;.gitignore&lt;/code&gt; file so as to prevent commiting all &lt;code&gt;node_modules&lt;/code&gt; folders and files before we configure Webpack.&lt;/p&gt;

&lt;p&gt;Next, create a file under the project’s root directory and save it as &lt;code&gt;webpack.config.js&lt;/code&gt;:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Go ahead and run &lt;code&gt;$ npx webpack&lt;/code&gt; inside your terminal. You should see a new &lt;code&gt;.tmp/dist&lt;/code&gt; folder was automatically created after bundling the assets with Webpack, and inside of it, you should end up with a &lt;code&gt;style.css&lt;/code&gt;, a &lt;code&gt;site.min.js&lt;/code&gt; and a &lt;code&gt;style.min.js&lt;/code&gt; files.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8yOCqtbI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/pmallol/middleman-webpack-demo/master/screenshots/screenshot-1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8yOCqtbI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/pmallol/middleman-webpack-demo/master/screenshots/screenshot-1.jpg" alt="Screenshot of Webpack's output in a terminal"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nice!&lt;/p&gt;

&lt;p&gt;Ok, so now that we made sure our files are being handled properly by Webpack, we need to make Middleman incorporate them when developing and building our app.&lt;/p&gt;

&lt;p&gt;Open the &lt;code&gt;config.rb&lt;/code&gt; file, where Middleman’s configuration lives, and add the following lines -we’re telling Middleman how to handle assets and where our new &lt;code&gt;.css&lt;/code&gt; and &lt;code&gt;.js&lt;/code&gt; files actually are-:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Finally, open up &lt;code&gt;./source/layouts/layout.erb&lt;/code&gt;, and replace the assets link helper inside the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; tag of the application’s layout with the following two lines -asset’s file names have changed a tiny bit-:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Check everything’s working ok by starting your application again with &lt;code&gt;$ bundle exec middleman&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Modify either &lt;code&gt;./source/stylesheets/site.css.scss&lt;/code&gt; or &lt;code&gt;./source/javascripts/site.js&lt;/code&gt; and open the browser at &lt;a href="https://localhost:4567"&gt;https://localhost:4567&lt;/a&gt; to see the changes reflected live:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tLI28mob--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/pmallol/middleman-webpack-demo/master/screenshots/screenshot-2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tLI28mob--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/pmallol/middleman-webpack-demo/master/screenshots/screenshot-2.jpg" alt="Screenshot of a Middleman app running in a browser at http://localhost:4567/ with dev tools open"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here I’ve changed the &lt;code&gt;background-color&lt;/code&gt; property to “powderblue” and added a &lt;code&gt;console.log(“Hello World”);&lt;/code&gt; to the JavaScript file.&lt;/p&gt;

&lt;p&gt;Great! You can further improve Webpack’s configuration by adding specific settings to your production environment and create a separate configuration file for both production and development.&lt;/p&gt;

&lt;p&gt;We won’t get to cover that in this blogpost. That’s it for now on all matters regarding Webpack as an external service.&lt;/p&gt;

&lt;p&gt;Coming next, we’re going to dockerize all of this!&lt;/p&gt;

</description>
      <category>webpack</category>
      <category>middleman</category>
      <category>githubpages</category>
      <category>docker</category>
    </item>
  </channel>
</rss>
