<?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: Matt Lehrer</title>
    <description>The latest articles on DEV Community by Matt Lehrer (@mattlehrer).</description>
    <link>https://dev.to/mattlehrer</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%2F445495%2F527e09e4-4996-4fcb-95de-fb39709402e2.png</url>
      <title>DEV Community: Matt Lehrer</title>
      <link>https://dev.to/mattlehrer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mattlehrer"/>
    <language>en</language>
    <item>
      <title>How to Setup TailwindCSS for a Custom Ghost Theme</title>
      <dc:creator>Matt Lehrer</dc:creator>
      <pubDate>Sun, 30 Aug 2020 21:30:20 +0000</pubDate>
      <link>https://dev.to/mattlehrer/how-to-setup-tailwindcss-with-a-custom-ghost-theme-5hmk</link>
      <guid>https://dev.to/mattlehrer/how-to-setup-tailwindcss-with-a-custom-ghost-theme-5hmk</guid>
      <description>&lt;p&gt;&lt;a href="https://ghost.org" rel="noopener noreferrer"&gt;Ghost&lt;/a&gt; has a ton going for it. But existing themes are never exactly right and I wanted to be able to make changes with &lt;a href="https://tailwindcss.com" rel="noopener noreferrer"&gt;TailwindCSS&lt;/a&gt; and couldn't find a fresh start -- &lt;a href="https://forum.ghost.org/t/gulp-tailwind-template-example/16440" rel="noopener noreferrer"&gt;despite finding others looking&lt;/a&gt; for this, too. If you're in the same position, this post is for you. &lt;/p&gt;

&lt;p&gt;I use the official &lt;a href="https://github.com/TryGhost/Starter" rel="noopener noreferrer"&gt;Ghost Starter Theme&lt;/a&gt; as a jumping off point, though you should be able to do this with any existing theme.&lt;/p&gt;

&lt;p&gt;You'll need the &lt;a href="https://ghost.org/docs/install/local/" rel="noopener noreferrer"&gt;Ghost CLI&lt;/a&gt; installed.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm install ghost-cli@latest -g


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Start by creating a fresh directory.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

mkdir ghost-project &amp;amp;&amp;amp; cd "$_"


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then &lt;a href="https://ghost.org/docs/install/local/" rel="noopener noreferrer"&gt;install Ghost locally&lt;/a&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

ghost install local


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After the installation is done, you'll have a running ghost instance at &lt;a href="http://localhost:2368" rel="noopener noreferrer"&gt;http://localhost:2368&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next create a new repository based on the &lt;a href="https://github.com/TryGhost/Starter" rel="noopener noreferrer"&gt;Ghost Starter Theme&lt;/a&gt; using the "Use this template" green button on Github.&lt;br&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%2Fjstpaox6negkmsjandq8.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%2Fjstpaox6negkmsjandq8.png" alt="Use this template"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;cd into the themes directory and clone the new repo, with your username and the name of the repo:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

cd content/themes
git clone git@github.com:&amp;lt;your-github-username/&amp;lt;your-new-repo-name&amp;gt;.git ghost-starter-with-tailwind


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The default Casper theme will be in that directory as a sibling, if you want to see how that theme handles anything.&lt;/p&gt;

&lt;p&gt;The Ghost Starter Theme uses yarn, so use that to install dependencies. cd into your new theme directory and then run yarn:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

cd ghost-starter-with-tailwind
yarn


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This is a good time to change the name of the theme to whatever you'd like. The name field at the top of the package.json ('﻿﻿﻿﻿ghost-starter-theme' when you open the file) is what shows up in Ghost's admin interface.&lt;/p&gt;

&lt;p&gt;You can now install and setup Tailwind.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

yarn add tailwindcss
npx tailwindcss init


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Add the Tailwind base styles to ./assets/css/screen.css:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="c"&gt;/* assets/css/screen.css */&lt;/span&gt;

&lt;span class="c"&gt;/* ... */&lt;/span&gt;

&lt;span class="c"&gt;/* Base components */&lt;/span&gt;
&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s1"&gt;"vars.css"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s1"&gt;"components/global.css"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s1"&gt;"components/forms.css"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s1"&gt;"components/buttons.css"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c"&gt;/* Ghost components */&lt;/span&gt;
&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s1"&gt;"ghost/header.css"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s1"&gt;"ghost/content.css"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s1"&gt;"ghost/readmore.css"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s1"&gt;"ghost/members.css"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s1"&gt;"ghost/errors.css"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s1"&gt;"ghost/footer.css"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s1"&gt;"ghost/badge.css"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c"&gt;/* Tailwind - add this part */&lt;/span&gt;
&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s1"&gt;"tailwindcss/base"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s1"&gt;"tailwindcss/components"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s1"&gt;"tailwindcss/utilities"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c"&gt;/* ... */&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As you replace styles with Tailwind classes, you can remove the other imports but leave them there for now.&lt;/p&gt;

&lt;p&gt;The Starter uses Gulp and gulp-postcss, so we'll roughly follow that part of the &lt;a href="https://tailwindcss.com/docs/installation" rel="noopener noreferrer"&gt;Tailwind installation instructions&lt;/a&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// gulpfile.js&lt;/span&gt;

&lt;span class="c1"&gt;// import tailwind at the top of the file&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tailwind&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;tailwindcss&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// ...&lt;/span&gt;

&lt;span class="c1"&gt;// add tailwind to the css processors list, around line 43:&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;css&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;done&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;processors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="nx"&gt;easyimport&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nf"&gt;colorFunction&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="nf"&gt;tailwind&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="c1"&gt;// add this&lt;/span&gt;
        &lt;span class="nf"&gt;autoprefixer&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="nf"&gt;cssnano&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next, restart ghost to make sure we're catching all the new files and the name change on the theme, if you made one. It shouldn't matter what your working directory is. You can run this from the theme directory.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

ghost restart


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then start all the theme file watchers, so that changes to css and the handlebars files are picked up by Ghost. This you have to run from the theme directory (/content/themes/ghost-starter-with-tailwind or whatever you named it).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

yarn dev


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Setup Ghost admin with a name for the admin and the blog, an email and a password at &lt;a href="http://localhost:2368/ghost" rel="noopener noreferrer"&gt;http://localhost:2368/ghost&lt;/a&gt; and then hit skip at the bottom of the next page when it asks to invite teammates.&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%2Fjle0nzw92n3g4x81b3c7.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%2Fjle0nzw92n3g4x81b3c7.png" alt="Account setup"&gt;&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%2Fy7gbjif2ao2yxr7zflx7.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%2Fy7gbjif2ao2yxr7zflx7.png" alt="Skip"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Almost done now. Go into Ghost's settings and activate the new theme. Click into Settings &amp;gt; Design.&lt;br&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%2F0v3azb1cy0avfn2jm5zb.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%2F0v3azb1cy0avfn2jm5zb.png" alt="Design settings"&gt;&lt;/a&gt;&lt;br&gt;
And then all the way at the bottom of the Design Settings page, click activate on the new theme.&lt;br&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%2Fm2x97s424ajep4dx8kvc.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%2Fm2x97s424ajep4dx8kvc.png" alt="Activate theme"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, you can start adding Tailwind classes to your handlebars templates. If something doesn't work quite right, try removing CSS and imports from screen.css. Your changes should be picked up by the watchers, but there's no autoreload in the browser. So refresh after saving any changes.&lt;/p&gt;

&lt;p&gt;This should get you started. I have &lt;a href="https://github.com/mattlehrer/ghost-starter-with-tailwind/tree/ccafef103f8da561b643ff56a5bd0be55dea9467" rel="noopener noreferrer"&gt;the code to this point on Github&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;I'll follow up with another post on how I converted the existing CSS to Tailwind, adding &lt;a href="https://tailwindcss.com/docs/typography-plugin" rel="noopener noreferrer"&gt;Tailwind's typography plugin&lt;/a&gt; for a good starting point for post pages, and &lt;a href="https://tailwindcss.com/docs/controlling-file-size#enabling-manually" rel="noopener noreferrer"&gt;purging unused CSS&lt;/a&gt; on Ghost Pro, which required manual purging when I used it.&lt;/p&gt;

</description>
      <category>ghost</category>
      <category>tailwindcss</category>
      <category>theme</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
