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

Allow data option to prepend style to scss, less, stylus blocks #95

Merged
merged 2 commits into from
May 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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