Runners
Boss CSS exposes programmatic runners from the root package so you can drive build/watch/compile/PostCSS work without the CLI.
import {
runBuild,
runWatch,
runCompile,
runPostcss,
} from 'boss-css'
runBuild
const result = await runBuild(userConfig, { baseDir: process.cwd() })
Returns:
filesParsed: number of parsed source filescssPath: absolute path to the global stylesheet (ornullfor runtime-only unlessruntime.globals: 'file')cssBytes: CSS size in bytesdurationMs: build time in millisecondsboundaryPaths: array of resolved.boss.cssboundary files (when CSS boundaries are enabled)
runWatch
const watcher = await runWatch(userConfig, {
onBuild(result) {
console.log(result.cssPath)
},
onError(error) {
console.error(error)
},
onReady() {
console.log('watch ready')
},
})
// later
await watcher.close()
Notes:
runWatchemits a build immediately, then rebuilds on file changes.close()stops file watching and fires theonSessionstop hook.
runCompile
const result = await runCompile({ config: userConfig, prod: false })
This is the programmatic equivalent of npx boss-css compile.
runPostcss
runPostcss is the internal helper used by the PostCSS plugin:
import postcss from 'postcss'
import { runPostcss } from 'boss-css'
const processor = postcss([
async (root, result) => {
await runPostcss(root, result, { baseDir: process.cwd() })
},
])
Auto-start dev server
When the devtools plugin is enabled and NODE_ENV is not production, runWatch and runPostcss auto-start the Boss dev server unless devServer.autoStart is set to false.
// .bo$$/config.js
export default {
devServer: {
autoStart: false,
},
}