-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (42 loc) · 1.33 KB
/
Copy pathindex.js
File metadata and controls
50 lines (42 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { basename, win32, posix } from "node:path";
import { readFile } from "node:fs/promises";
import browserslist from "browserslist";
import { transform, browserslistToTargets } from "lightningcss";
export default function lightningcss(config = {}) {
const { files, options } = config;
const transformOpts = { minify: true, ...options };
if (!("targets" in transformOpts))
transformOpts["targets"] = browserslistToTargets(browserslist());
return {
name: "lightningcss",
async generateBundle() {
const filesToTransform = files.map(async (file) => {
file = file.split(win32.sep).join(posix.sep);
const filename = basename(file);
console.debug(
"\x1b[1;38;2;255;203;78m%s\x1b[0m",
`⚡ [rollup-lightningcss] Processing ${file}...`
);
let { code, map } = transform({
...transformOpts,
filename: filename,
code: await readFile(file),
});
this.emitFile({
type: "asset",
fileName: filename,
source: code,
});
// if sourceMaps is enabled
if (map) {
this.emitFile({
type: "asset",
fileName: `${filename}.map`,
source: map.toString(),
});
}
});
await Promise.all(filesToTransform);
},
};
}