feat: minify tailwind css in prod + other enhancements (#2059)
This commit is contained in:
+12
-3
@@ -1,6 +1,7 @@
|
||||
import { Plugin, PluginMiddleware, ResolvedFreshConfig } from "../server.ts";
|
||||
import tailwindCss, { Config } from "tailwindcss";
|
||||
import postcss from "npm:postcss@8.4.31";
|
||||
import cssnano from "npm:cssnano@6.0.1";
|
||||
import * as path from "https://deno.land/std@0.207.0/path/mod.ts";
|
||||
import { walk } from "https://deno.land/std@0.207.0/fs/walk.ts";
|
||||
|
||||
@@ -16,8 +17,7 @@ async function initTailwind(
|
||||
|
||||
let tailwindConfig: Config = {
|
||||
content: [
|
||||
`${relativeRoot}routes/**/*.{ts,tsx,js,jsx,mjs,cjs}`,
|
||||
`${relativeRoot}components/**/*.{ts,tsx,js,jsx,mjs,cjs}`,
|
||||
`${relativeRoot}{routes,components,islands}/**/*.{ts,tsx,js,jsx,mjs,cjs}`,
|
||||
],
|
||||
};
|
||||
|
||||
@@ -39,6 +39,7 @@ async function initTailwind(
|
||||
}
|
||||
|
||||
if (importedConfig === null) continue;
|
||||
importedConfig.content = importedConfig.content ?? [];
|
||||
|
||||
if (!Array.isArray(importedConfig.content)) {
|
||||
throw new Error(`Expected tailwind "content" option to be an array`);
|
||||
@@ -64,7 +65,15 @@ async function initTailwind(
|
||||
break;
|
||||
}
|
||||
|
||||
return postcss([tailwindCss(tailwindConfig)]);
|
||||
const plugins: postcss.AcceptedPlugin[] = [
|
||||
tailwindCss(tailwindConfig),
|
||||
];
|
||||
|
||||
if (!config.dev) {
|
||||
plugins.push(cssnano());
|
||||
}
|
||||
|
||||
return postcss(plugins);
|
||||
}
|
||||
|
||||
export default function tailwind(): Plugin {
|
||||
|
||||
Reference in New Issue
Block a user