Skip to content

Commit

Permalink
Merge pull request #462 from nobkd/glow-bun-css
Browse files Browse the repository at this point in the history
feat(glow): minify css with bun
  • Loading branch information
nobkd authored Feb 12, 2025
2 parents 4a81640 + 77c07d9 commit a4a3812
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 22 deletions.
27 changes: 10 additions & 17 deletions packages/glow/css/build.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
// Running: bun css/build.js
import { promises as fs } from 'node:fs'

import { transform, Features } from 'lightningcss'


async function minify(names, toname, include = 0) {
const raw = []
for (const name of names) {
raw.push(await fs.readFile(`css/${name}.css`, 'utf-8'))
}

const min = transform({
code: Buffer.from(raw.join('\n')),
async function minify(names, toname) {
const min = await (await Bun.build({
entrypoints: names.map(name => `css/${name}.css`),
minify: true,
include

}).code?.toString()
throw: true,
experimentalCss: true,
})).outputs.map(async file => await file.text())

const to = `minified/${toname}.css`
await fs.mkdir('minified', { recursive: true })
await fs.writeFile(to, min)
console.log('>', to, min.length)
console.log('>', to, (await fs.stat(to)).size)
}


await minify(['syntax', 'markers'], 'syntax', Features.Nesting)
await minify(['syntax'], 'syntax.nano', Features.Nesting)
await minify(['syntax', 'markers'], 'syntax')
await minify(['syntax'], 'syntax.nano')

3 changes: 2 additions & 1 deletion packages/glow/minified/syntax.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/glow/minified/syntax.nano.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions packages/glow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
"node": ">= 18"
},
"scripts": {
"css": "bun ./css/build.js",
"test": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js --runInBand"
},
"devDependencies": {
"lightningcss": "^1.27.0"
},
"jest": {
"setupFilesAfterEnv": [
"jest-extended/all",
Expand Down

0 comments on commit a4a3812

Please sign in to comment.