-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathbuild-css.ts
More file actions
54 lines (46 loc) · 1.56 KB
/
Copy pathbuild-css.ts
File metadata and controls
54 lines (46 loc) · 1.56 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
51
52
53
54
// Privilege separation module for dependencies that can only affect CSS output.
/// <reference lib="deno.worker" />
import Browsers from 'autoprefixer/lib/browsers.js';
import Prefixes from 'autoprefixer/lib/prefixes.js';
import {agents} from 'caniuse-lite/dist/unpacker/agents.js';
import dataPrefixes from 'autoprefixer/data/prefixes.js';
import browserslist from 'browserslist';
import postcss from 'postcss';
import * as sass from 'sass';
import type {CssRequest, CssResponse} from './build.ts';
// simplified from autoprefixer/index.js
const browsers = new Browsers(agents, browserslist.defaults, {}, {
// avoid needing excessive privileges to search for nonexistent configuration
stats: {},
});
const prefixes = new Prefixes(dataPrefixes, browsers, {});
const cssProcessor = postcss([
{
postcssPlugin: 'autoprefixer',
prepare: result => ({
OnceExit(root) {
prefixes.processor.remove(root, result);
prefixes.processor.add(root, result);
},
}),
},
]);
self.onmessage = (e: MessageEvent<CssRequest>) => {
const {
messageId,
resolvedSource,
} = e.data;
const sassResult = sass.compile(resolvedSource, {
style: 'compressed',
});
const result = cssProcessor.process(sassResult.css, {
from: undefined,
map: false,
});
self.postMessage({
messageId,
css: result.css,
loadedUrls: sassResult.loadedUrls.map(url => url.href),
warnings: result.warnings().map(String),
} satisfies CssResponse);
};