Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit 4f31e4f

Browse files
authored
Allow data option to prepend style to scss, less, stylus blocks (#95)
* Allow data option to prepend style in scss, less, stylus * Add default config for less
1 parent f8110f6 commit 4f31e4f

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

src/options.js

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export default {
6060
// Config for node-sass.
6161
scss: {},
6262

63+
// Config for less.
64+
less: {},
65+
6366
// Config for stylus.
6467
stylus: {},
6568

src/style/less.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
export default async function (style, options) {
22
const less = require('less')
3-
const { css, map } = await less.render(style.code, {
4-
sourceMap: {
5-
sourceMapFullFilename: style.id,
6-
sourceMapFileInline: false
7-
},
8-
...options.less
9-
})
3+
const { css, map } = await less.render(
4+
'data' in options.less ? `${options.less.data}\n${style.code}` : style.code,
5+
{
6+
sourceMap: {
7+
sourceMapFullFilename: style.id,
8+
sourceMapFileInline: false
9+
},
10+
...options.less
11+
}
12+
)
1013

1114
style.$compiled = {
1215
code: css.toString(),

src/style/scss.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default function (style, options) {
55
debug(`SASS: ${style.id}`)
66
const { css, map } = sass.renderSync({
77
file: style.id,
8-
data: style.code,
8+
data: 'data' in options.scss ? `${options.scss.data}\n${style.code}` : style.code,
99
omitSourceMapUrl: true,
1010
sourceMap: true,
1111
outFile: style.id,

src/style/stylus.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export default async function (style, options) {
22
const stylus = require('stylus')
3-
const stylusObj = stylus(style.code, {...options.stylus})
4-
.set('filename', style.id)
5-
.set('sourcemap', {
6-
'comment': false
7-
})
3+
const stylusObj = stylus('data' in options.stylus ? `${options.stylus.data}\n${style.code}` : style.code, { ...options.stylus })
4+
.set('filename', style.id)
5+
.set('sourcemap', {
6+
'comment': false
7+
})
88

99
const code = await stylusObj.render()
1010
const map = stylusObj.sourcemap

0 commit comments

Comments
 (0)