Browser extensions - adding Tailwind CSS

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
I really enjoy reading chrome extension article series 🧑💻.
Keep writing ♥️.
Glad you do, I have a couple more coming. Anything specific you'd love to learn about?
Now that we have our Browser extension up and running with Tailwind CSS and Parcel let's look at how we can make it more interactive. You can choose any framework you are familiar with. I decided to go with React for this one. The idea is to add Reac...
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

Yesterday we made our very first new tab browser extension. However, it was solely powered by plain CSS. This can become super hard to maintain over time, so let's see if we can automate much of it by introducing Tailwind CSS.
The main benefit of adding Tailwind is that it can only use its auto-purge option to include classes we are using on the page.
To handle the builds, I will also add Parcel, a super slim bundling tool we can use to do the heavy lifting.
If you like to follow this article, you can take the following GitHub repo as the starting point.
As we had a plain HTML starter before, we first have to init a package file.
npm init -y
Open the project and execute the following commands for this project in the terminal.
npm i parcel tailwindcss
This will install Parcel and Tailwind CSS packages.
Then we also need some dev dependencies.
npm i -D parcel-reporter-static-files-copy postcss-cli
This will install the Parcel static file copier and postCSS CLI. We will use these to clean up our build process.
And that's already it. We now have all the needed packages.
Since we installed the Parcel static file reporter, we can leverage its powers to move files that never change to our dist output.
Create a static folder in the root of your project, then move the manifest and the icons folder inside of it.
For it to work, we also need to create a .parcelrc file and put the following contents inside.
{
"extends": ["@parcel/config-default"],
"reporters": ["parcel-reporter-static-files-copy"]
}
This will ensure the static directory is always copied to our dist output.
Next, we want to look at how we can introduce the Tailwind setup to work.
First of all, add a .postcssrc.json file in the root project, this is a postCSS config file, but since it's built into Parcel, they will handle most of the config.
Put the following lines inside of this file.
{
"plugins": {
"tailwindcss": {}
}
}
Next up, create the Tailwind config file by running the following command.
npx tailwind init
You can modify it to look like this:
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['*.html'],
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
};
Now open up the existing css/style.css file and replace everything inside with the following lines.
@tailwind base;
@tailwind components;
@tailwind utilities;
And that's it. Our tailwind config is already done.
Now that we have all the individual players lined up, we need to combine them.
This magic happens in the package.json file.
Add the following scripts to the file.
{
...
"scripts": {
"prebuild": "rm -rf dist .parcel-cache",
"watch": "parcel watch new-tab.html",
"build": "parcel build new-tab.html"
},
}
We state that any prebuild should remove the parcel cache and dist directory.
The watch command can be used while you are developing the extension, and it will auto-reload for you.
Once satisfied, you can generate a final build by running the following command.
npm run build
To test it out, you have to follow the steps described in this article, but pick the dist folder to be loaded.
And that's it! You now have an extension powered by Tailwind CSS and Parcel.
You can also find the complete code sample on this GitHub repo.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter