Skip to content

Commit

Permalink
feat: minify css with bun
Browse files Browse the repository at this point in the history
  • Loading branch information
nobkd committed Jan 26, 2025
1 parent 5ecb5ac commit 2221e69
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
Binary file modified bun.lockb
Binary file not shown.
21 changes: 11 additions & 10 deletions packages/glow/css/build.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
// Running: bun css/build.js
import { promises as fs } from 'node:fs'

import { transform, Features } from 'lightningcss'


async function minify(names, toname, include = 0) {
async function minify(names, toname) {
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')),
const filename = 'tmp.css'
await fs.writeFile(filename, raw.join('\n'))

const min = await (await Bun.build({
entrypoints: [filename],
minify: true,
include
throw: true,
})).outputs[0].text()

}).code?.toString()
await fs.rm(filename)

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


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

2 changes: 1 addition & 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.

5 changes: 1 addition & 4 deletions packages/glow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@
"type": "git"
},
"engines": {
"bun": ">= 1",
"bun": ">= 1.1.34",
"node": ">= 18"
},
"scripts": {
"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 2221e69

Please sign in to comment.