Skip to content

Commit

Permalink
[web] esbuild-plugin-tailwindcss doesn't work with inline, use postcss
Browse files Browse the repository at this point in the history
  • Loading branch information
notandy committed Oct 28, 2024
1 parent b014b45 commit b235f1d
Show file tree
Hide file tree
Showing 4 changed files with 721 additions and 328 deletions.
19 changes: 16 additions & 3 deletions web/esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as esbuild from 'esbuild'
import { default as pkg } from './package.json' with {type: 'json'}
import { tailwindPlugin } from 'esbuild-plugin-tailwindcss';
import inlineImportPlugin from 'esbuild-plugin-inline-import';
import chalk from "chalk";
import imageInline from "esbuild-plugin-inline-image";
import postcss from "postcss";
import autoprefixer from "autoprefixer";
import tailwindcss from "tailwindcss"

const isProduction = process.env.NODE_ENV === "production"
const args = process.argv.slice(2)
Expand All @@ -22,8 +24,19 @@ let ctx = await esbuild.context({
entryPoints: [pkg.source],
outdir: "public/build",
plugins: [
inlineImportPlugin({}),
tailwindPlugin({}),
inlineImportPlugin({
transform: async (contents, args) => {
let path = args.path
if (path.endsWith(".css")) {
let {css} = await postcss([tailwindcss, autoprefixer]).process(contents, {
from: path,
to: path,
})
return css
}
return {contents}
},
}),
imageInline({limit: 10240, extensions: ["png", "jpg", "jpeg", "gif"]}), // 10Kb
],
})
Expand Down
Loading

0 comments on commit b235f1d

Please sign in to comment.