Skip to content

Instantly share code, notes, and snippets.

@rgpublic
Created November 4, 2024 13:41
Show Gist options
  • Save rgpublic/2f877644c0ed8c45706382172c7cfa32 to your computer and use it in GitHub Desktop.
Save rgpublic/2f877644c0ed8c45706382172c7cfa32 to your computer and use it in GitHub Desktop.
LightningCSS Compile
#!/usr/bin/env node
import lightningcss from '/usr/lib/node_modules/lightningcss/node/index.js';
import fs from 'fs/promises';
import * as path from 'path';
const {transform} = lightningcss;
if (process.argv.length!=4) {
console.log('Usage: compile.js <inputfile> <outputfile>');
process.exit(1);
}
let infile=process.argv[2];
let outfile=process.argv[3];
const codeBuffer=await fs.readFile(infile);
const mapBuffer=await fs.readFile(infile+".map");
let { code, map } = transform({
filename: 'style.css',
code: Buffer.from(codeBuffer),
inputSourceMap: Buffer.from(mapBuffer),
minify: true,
sourceMap: true
});
await fs.writeFile(outfile,code);
await fs.writeFile(outfile+".map",map);
{
"type": "module"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment