Skip to content

Commit f7e3d5a

Browse files
Gameghostifygiuseppeg
authored andcommitted
Update index.js (#25)
Allows for `settings.sassOptions.data` field to be specified
1 parent 82aeda6 commit f7e3d5a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

index.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const sass = require('node-sass')
2-
const path = require('path')
1+
const sass = require('node-sass');
2+
const path = require('path');
33

44
module.exports = (css, settings) => {
55
const cssWithPlaceholders = css
@@ -12,14 +12,23 @@ module.exports = (css, settings) => {
1212

1313
// Add the directory containing the current file to includePaths to enable relative
1414
// imports, only works when the filename is provided
15-
const includePaths = settings.sassOptions && settings.sassOptions.includePaths || []
15+
const includePaths = settings.sassOptions && settings.sassOptions.includePaths || [];
16+
1617
if (settings.babel && settings.babel.filename) {
1718
includePaths.push(path.dirname(settings.babel.filename));
1819
}
1920

20-
const preprocessed = sass.renderSync(Object.assign({
21-
data: cssWithPlaceholders
22-
}, settings.sassOptions, { includePaths })).css.toString()
21+
// Prepend option data to cssWithPlaceholders
22+
const optionData = settings.sassOptions && settings.sassOptions.data || "";
23+
const data = optionData + "\n" + cssWithPlaceholders;
24+
25+
const preprocessed = sass.renderSync(
26+
Object.assign(
27+
{},
28+
settings.sassOptions,
29+
{ data },
30+
{ includePaths }
31+
)).css.toString()
2332

2433
return preprocessed
2534
.replace(/styled-jsx-placeholder-(\d+)-(\w*\s*[),;!{])/g, (_, id, p1) =>

0 commit comments

Comments
 (0)