Skip to content

Commit

Permalink
feat(deps): install tailwind
Browse files Browse the repository at this point in the history
  • Loading branch information
masonmcelvain committed Oct 15, 2023
1 parent 679082a commit 1bb72ff
Show file tree
Hide file tree
Showing 9 changed files with 9,922 additions and 6,883 deletions.
1 change: 1 addition & 0 deletions .prettierrc.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
tabWidth = 3
plugins = ["prettier-plugin-tailwindcss"]
30 changes: 28 additions & 2 deletions build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import { z } from "zod";
const TargetSchema = z.union([z.literal("chrome"), z.literal("firefox")]);
type Target = z.infer<typeof TargetSchema>;
const target = TargetSchema.parse(process.env.TARGET);
const NodeEnvSchema = z.union([
z.literal("development"),
z.literal("production"),
]);
type NodeEnv = z.infer<typeof NodeEnvSchema>;
const nodeEnv = NodeEnvSchema.parse(process.env.NODE_ENV);

const cleanupPlugin = ({ target }: { target: Target }): esbuild.Plugin => ({
name: "cleanup",
Expand All @@ -25,6 +31,25 @@ const copyAssetsPlugin = ({ target }: { target: Target }): esbuild.Plugin => ({
},
});

type TailwindPluginProps = {
target: Target;
nodeEnv: NodeEnv;
};
const tailwindPlugin = ({
target,
nodeEnv,
}: TailwindPluginProps): esbuild.Plugin => ({
name: "tailwind",
setup(build) {
build.onStart(() => {
const minify = nodeEnv === "production" ? "--minify" : "";
execSync(
`tailwindcss -i src/globals.css -o dist/${target}/output.css ${minify}`,
);
});
},
});

const zipPlugin = ({ target }: { target: Target }): esbuild.Plugin => ({
name: "zip",
setup(build) {
Expand All @@ -40,13 +65,14 @@ const baseOptions: esbuild.BuildOptions = {
loader: {
".html": "copy",
},
target: ["chrome58", "firefox57"],
outdir: `dist/${target}`,
plugins: [
cleanupPlugin({ target }),
copyAssetsPlugin({ target }),
tailwindPlugin({ target, nodeEnv }),
zipPlugin({ target }),
],
target: ["chrome58", "firefox57"],
outdir: `dist/${target}`,
};

async function build() {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
"husky": "8.0.3",
"lint-staged": "15.0.1",
"prettier": "3.0.3",
"prettier-plugin-tailwindcss": "0.5.6",
"tailwindcss": "3.3.3",
"ts-node": "10.9.1",
"typescript": "5.2.2",
"web-ext": "7.8.0",
Expand Down
Loading

0 comments on commit 1bb72ff

Please sign in to comment.