-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
index.js
40 lines (34 loc) · 1.07 KB
/
index.js
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
import {Buffer} from 'node:buffer';
import applySourceMap from 'vinyl-sourcemaps-apply';
import autoprefixer from 'autoprefixer';
import postcss from 'postcss';
import {gulpPlugin} from 'gulp-plugin-extras';
export default function gulpAutoprefixer(options) {
return gulpPlugin('gulp-autoprefixer', async file => {
try {
const result = await postcss(autoprefixer(options)).process(file.contents.toString(), {
map: file.sourceMap ? {annotation: false} : false,
from: file.path,
to: file.path,
});
file.contents = Buffer.from(result.css);
if (result.map && file.sourceMap) {
const map = result.map.toJSON();
map.file = file.relative;
map.sources = map.sources.map(() => file.relative);
applySourceMap(file, map);
}
const warnings = result.warnings();
if (warnings.length > 0) {
console.log('gulp-autoprefixer:', '\n ' + warnings.join('\n '));
}
return file;
} catch (error) {
if (error.name === 'CssSyntaxError') {
error.message += error.showSourceCode();
error.isPresentable = true;
}
throw error;
}
});
}