Code Monkey home page Code Monkey logo

hugo-starter-tailwind-basic's Introduction

Hugo Basic Starter for TailwindCSS v3.x

Netlify Status

A very simple starter set up with TailwindCSS and its typography plugin and a build setup using PostCSS and PurgeCSS (when running the production build).

In the preview deployment on Netlify it currently has a 100 score on both mobile and desktop on Google PageSpeed.

This setup can be used both as a starter project and a theme.

As a Project

npm install
hugo server

As a Theme

Import github.com/bep/hugo-starter-tailwind-basic/v3 (use github.com/bep/hugo-starter-tailwind-basic/v2 if you want/need Tailwind 2.x.) into your project, and then run:

hugo mod npm pack
npm install

You need to add (something like) this to your hugo.toml:

[module]
  [module.hugoVersion]
    extended = false
    min      = "0.112.0"
  [[module.mounts]]
    source = "assets"
    target = "assets"
  [[module.mounts]]
    source = "hugo_stats.json"
    target = "assets/watching/hugo_stats.json"

[build]
  writeStats = true
  [[build.cachebusters]]
    source = "assets/watching/hugo_stats\\.json"
    target = "styles\\.css"
  [[build.cachebusters]]
    source = "(postcss|tailwind)\\.config\\.js"
    target = "css"
  [[build.cachebusters]]
    source = "assets/.*\\.(js|ts|jsx|tsx)"
    target = "js"
  [[build.cachebusters]]
    source = "assets/.*\\.(.*)$"
    target = "$1"

Then run your project as usual.

hugo-starter-tailwind-basic's People

Contributors

0xflotus avatar bep avatar cmlnet avatar imfing avatar regisphilibert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

hugo-starter-tailwind-basic's Issues

WhitelistPatterns not working anymore in v2

Hello,

I just upgraded to v2, and saw that my whitelist do not work anymore.
And looking at the new tailwind.config.js i can't find a way to put my specific conf (I'm a tailwind/purgecss noob).

This what was working fine in v1.
Any tip/advice for adapting the v2 conf file ? Thanks.

// Source : https://github.com/bep/hugo-starter-tailwind-basic/blob/master/tailwind.config.js
// Modified for better whitelisting (bootstrap/venobox, ...)

const theme = require('tailwindcss/defaultTheme');
const typography = require('@tailwindcss/typography');

//const colorBrand = 'var(--color-pretty)';

// Utils
const round = (num) => num.toFixed(7).replace(/(\.[0-9]+?)0+$/, '$1').replace(/\.0$/, '');
const rem = (px) => `${round(px / 16)}rem`;
const em = (px, base) => `${round(px / base)}em`;
const px = (px) => `${px}px`;

module.exports = {
	important: true, // See https://tailwindcss.com/docs/configuration#important
	experimental: {
		// See https://github.com/tailwindlabs/tailwindcss/pull/2159
		applyComplexClasses: true
	},
	purge: {
		enabled: process.env.HUGO_ENVIRONMENT === 'production',
		content: [ './hugo_stats.json' ],
		mode: 'all',
		options: {
         //whitelist: [ 'pl-1', 'pl-3' ],
         whitelistPatterns: [
            // pour AOS plugin (Tested OK)
            /data-aos/,
            /data-aos^/,
            /^fade/,
            /^flip/,
            /^aos/,
            // pour bootstrap (Tested OK)
            /^btn-/,
            // pour MsgBox bootstrap (Tested OK)
            /show/,
            // pour venobox (Tested OK)
            /data-autoplay/,
            /data-vbtype/,
            /venoframe/,
            /vbvid/,
            /vbox-open/,
            /vbox-overlay/,
         ],
			defaultExtractor: (content) => {
				let els = JSON.parse(content).htmlElements;
				els = els.tags.concat(els.classes, els.ids);
				return els;
			}
		}
	},
	plugins: [ typography ]
};

Tailwind built in purge

// tailwind.config.js
module.exports = {
  purge: {
    enabled: process.env.HUGO_ENVIRONMENT === 'production',
    content: ['./layouts/**/*.html', './themes/**/*.html'],
  },
...

Is there any particular reason not to use the Tailwind v2 built in purge?

Styles in /public/css not being applied, and can't use [&>*] class

Styles get applied in localhost:1313but don't when I open the final index.html file inside public. The link tag in this file is as follows:

    <link href="/css/styles.min.52e3ba9573dbb62854822e4cadded642295dfdff0ce8c8908db7921c22e87145.css" rel="stylesheet" />

The path and file name are accurate. I also tried removing the numbers from the filename (I'm guessing these are added to prevent caching?) & updating the href but still no styles are being applied.

I was wondering if this might be also causing my 2nd problem. Since tailwind v3.1, you can use [&>*] as a sort of selector to apply tailwind classes to an element's children. Here's a working example that uses v3.3.3: https://play.tailwindcss.com/rq8YVDB3LG

This doesn't work when used in the starter template though. I ran npm list tailwindcss to check the installed version & got this:

[email protected] /home/sujal/programming/client-work/hugo-kamana-treks
├─┬ @tailwindcss/[email protected]
│ └── [email protected] deduped
└── [email protected]

Does the "tailwindcss": "^2.2.7" in package.hugo.json affect this? [&>*] works fine when I test it in a non-hugo project using the tailwind v3.3.3 binary. I tried updating tailwind inside the template to 3.3.3 as well but to no avail

Edit: Forgot to say that both the index.html & styles.css files in public don't have the [&>*] class

Ive notice all buildtime of hugo with tailwind is pretty damn slow

Hi, this has been issue with tailwind itself...
but there is a way to speed up buildtime, at the cost of not being able to use @apply

but i think the trade off is pretty good, since you dont usually use it
me personally...

https://nystudio107.com/blog/speeding-up-tailwind-css-builds

Ive notice the buildtime on this new starter app is 3.6 secs which is slow compare to other hugo site
which is below 500 ms without all the added stuffs...

Quck question, is esbuild the compiler being used to process css?
thats the fastest compiler yet tailwind is so slow...
Been trying to cut down the cold start boot time in my main project from 11secs now at 6 secs...
significant increase...
i think all starter template should be at least around 200ms from scratch...

Build Command "hugo" not working?

If i try the command "hugo" i got some errors. Is it possible to build this into the "public" folder.

i had an old version 0.68.1 installed. i'm sorry.
thanks for your awesome work on hugo.

Due to some reasons media queries are not effective!

Hi
I'm observing that due to some reasons things messed up. I don't know if it's in only my case or you guys configured it by choice.
Check the screenshot here:
image
See how even in mobile preview class with in media query (min-width: 768px) is overriding the default class. I'm confused!

I was excited to use this starter template by Bep and other but currently having bad time. BTW, I'm not new to tailwindcss.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.