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

Preprocess data option for styles #73

Merged
merged 3 commits into from
Jun 24, 2018
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
14 changes: 8 additions & 6 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,22 @@ export class SFCCompiler {
]
.concat(this.style.postcssPlugins)
.filter(Boolean)
const preprocessOptions =
(style.lang &&
this.style.preprocessOptions &&
this.style.preprocessOptions[style.lang]) ||
{}
const source = style.src ? this.read(style.src, filename) : style.content
const result = compileStyle(<any>{
source: style.src ? this.read(style.src, filename) : style.content,
source: preprocessOptions.data ? `${preprocessOptions.data}\n${source}` : source,
filename,
id: scopeId,
map: style.map,
scoped: style.scoped || false,
postcssPlugins,
postcssOptions: this.style.postcssOptions,
preprocessLang: style.lang,
preprocessOptions:
(style.lang &&
this.style.preprocessOptions &&
this.style.preprocessOptions[style.lang]) ||
{},
preprocessOptions,
trim: this.style.trim
})

Expand Down
18 changes: 18 additions & 0 deletions test/compile.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {createDefaultCompiler} from "../src"

it('should prepend data scss option to actual style', () => {
const compiler = createDefaultCompiler({
style: {
preprocessOptions : {
scss: {
data: `$testColor: red;`
}
}
}
})
const result = compiler.compileStyle('foo.vue', 'foo',
{type: 'style', lang: 'scss', content: '.foo_0{ color: $testColor }', map: undefined, attrs: {}, start: 1, end: 1}
);

expect(result.code).toEqual(expect.stringContaining('color: red'))
})
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy