Ready to craft a web extension thatโll dazzle Chrome and Firefox users? ๐ Letโs dive into this step-by-step adventure with Vite, Tailwind CSS, and a sprinkle of zippy magic! ๐ Buckle up and letโs make your browser shine! โจ
First, make sure youโve got Chrome and Firefox installed. These are your playgrounds for testing your epic extension. No browsers, no glory! ๐
Letโs get the party started by scaffolding your extension with a single command. Run this and watch the magic unfold! ๐
npm create vite-plugin-web-extension
If the command gods arenโt cooperating, you might need to manually hop into your project folder. Try this, or click your way to victory! ๐ฑ๏ธ
cd "app"
Pro tip: If itโs acting stubborn, navigate to the folder manually like a true explorer. ๐งญ
Feed your project the dependencies it craves. This command is like tossing a Happy Meal to your code! ๐
npm install
Time to make your extension look slick with Tailwind CSS. Install these beauts and get ready to style! ๐
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
Open pages/Popup.css
and drop in these Tailwind directives to give your popup some serious flair! ๐ฅ
@tailwind base;
@tailwind components;
@tailwind utilities;
pages/Popup.jsx
๐ ๏ธLetโs make your popup pop! Update pages/Popup.jsx
with this code to import Tailwind and say โHello Worldโ with style. ๐
import { useEffect } from "react";
import "./Popup.css";
export default function () {
useEffect(() => {
console.log("Hello from the popup! ๐");
}, []);
return <h1 className="font-bold text-3xl underline">Hello world! Test ๐</h1>;
}
tailwind.config.js
for Maximum Style ๐ชConfigure Tailwind to play nice with your files. Update tailwind.config.js
like so to ensure your styles are applied everywhere they should be! ๐
module.exports = {
content: [
'./public/**/*.html',
'./src/**/*.{js,jsx,ts,tsx}', // Point to your source files
],
theme: {
extend: {},
},
plugins: [],
};
Time to see your creation in action! Fire up the dev server and watch your extension come to life. ๐ฌ
npm run dev
Ready to package your extension for the world? Letโs create a shiny extension.zip
file. First, install the zipping tool:
npm i zip-a-folder
Then, create a zipScript.js
file to bundle your dist
folder into a neat little zip package. ๐ฌ
import { zip } from "zip-a-folder";
await zip("dist", "extension.zip");
package.json
for Easy Building ๐ ๏ธAdd these scripts to your package.json
to streamline building and zipping. Itโs like giving your project a turbo button! ๐
{
"scripts": {
"build": "vite build && node zipScript.js",
"zip": "node zipScript.js"
}
}
Congrats, youโve built a web extension thatโs ready to rock Chrome and Firefox! ๐ Load it up, test it out, and maybe add some extra pizzazz to make it yours. Now go conquer the browser world, you coding superhero! ๐ฆธโโ๏ธ๐พ
Made with โค๏ธ in Aotearoa.