Skip to content

Commit

Permalink
minify dynamically injected css
Browse files Browse the repository at this point in the history
  • Loading branch information
timche committed Jan 31, 2024
1 parent 4581bd9 commit 7fc02c7
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,29 @@ async function bundleContext(
esbuildOptions.plugins.push(
esbuildInline({
filter: /^tailwindInline:/,
transform: (content) =>
postcss(
getPostcssPlugins([getSrcPath(`${context}/**/*.{js,ts,tsx}`)]),
transform: async (content) => {
const css = await postcss(
getPostcssPlugins([getSrcPath(`${context}/**/*.{ts,tsx}`)]),
)
.process(content, { from: undefined })
.then((result) => result.css)
.catch((error) => {
console.error(error.message)
return ''
}),
})

if (!IS_DEV) {
return (
await esbuild.transform(css, {
loader: 'css',
minify: true,
target: TARGET_BROWSER.replace(' ', ''),
})
).code
}

return css
},
}),
)
}
Expand Down

0 comments on commit 7fc02c7

Please sign in to comment.