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

Commit

Permalink
Allow data option to prepend style to scss, less, stylus blocks (#95)
Browse files Browse the repository at this point in the history
* Allow data option to prepend style in scss, less, stylus

* Add default config for less
  • Loading branch information
znck committed May 14, 2017
1 parent f8110f6 commit 4f31e4f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/options.js
Expand Up @@ -60,6 +60,9 @@ export default {
// Config for node-sass.
scss: {},

// Config for less.
less: {},

// Config for stylus.
stylus: {},

Expand Down
17 changes: 10 additions & 7 deletions src/style/less.js
@@ -1,12 +1,15 @@
export default async function (style, options) {
const less = require('less')
const { css, map } = await less.render(style.code, {
sourceMap: {
sourceMapFullFilename: style.id,
sourceMapFileInline: false
},
...options.less
})
const { css, map } = await less.render(
'data' in options.less ? `${options.less.data}\n${style.code}` : style.code,
{
sourceMap: {
sourceMapFullFilename: style.id,
sourceMapFileInline: false
},
...options.less
}
)

style.$compiled = {
code: css.toString(),
Expand Down
2 changes: 1 addition & 1 deletion src/style/scss.js
Expand Up @@ -5,7 +5,7 @@ export default function (style, options) {
debug(`SASS: ${style.id}`)
const { css, map } = sass.renderSync({
file: style.id,
data: style.code,
data: 'data' in options.scss ? `${options.scss.data}\n${style.code}` : style.code,
omitSourceMapUrl: true,
sourceMap: true,
outFile: style.id,
Expand Down
10 changes: 5 additions & 5 deletions src/style/stylus.js
@@ -1,10 +1,10 @@
export default async function (style, options) {
const stylus = require('stylus')
const stylusObj = stylus(style.code, {...options.stylus})
.set('filename', style.id)
.set('sourcemap', {
'comment': false
})
const stylusObj = stylus('data' in options.stylus ? `${options.stylus.data}\n${style.code}` : style.code, { ...options.stylus })
.set('filename', style.id)
.set('sourcemap', {
'comment': false
})

const code = await stylusObj.render()
const map = stylusObj.sourcemap
Expand Down

0 comments on commit 4f31e4f

Please sign in to comment.