-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (28 loc) · 809 Bytes
/
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
'use strict';
const through = require('through2');
const PluginError = require('plugin-error');
const styleModuleTemplate = [
'import {css} from \'lit-element\';',
'export const styles = css`',
'{{styles}}`;',
].join('\n');
module.exports = () => {
return through.obj(function(file, encoding, callback) {
if (file.isNull()) {
callback(null, file);
return;
}
if (file.isStream()) {
callback(new PluginError('gulp-csslit', 'Streaming not supported'));
return;
}
try {
const content = file.contents.toString(encoding);
const result = styleModuleTemplate.replace(/{{styles}}/g, content);
file.contents = Buffer.from(result);
callback(null, file);
} catch (error) {
callback(new PluginError('gulp-csslit', error, {filename: file.path}))
}
});
};