From 6156b651b0ff0ee32dfaa5b647e4c0a8ac0ca9e4 Mon Sep 17 00:00:00 2001 From: Toni Martinez Date: Thu, 14 Jun 2018 10:15:31 +0200 Subject: [PATCH 1/3] Add data option in preprocessOption to allow define env variable in styles --- src/compiler.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index 0749263..e4b13e4 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -17,6 +17,7 @@ import postcssClean from './postcss-clean' import hash = require('hash-sum') import * as fs from 'fs' import * as path from 'path' +import os from'os' export interface TemplateOptions { compiler: VueTemplateCompiler @@ -168,8 +169,14 @@ 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({ - source: style.src ? this.read(style.src, filename) : style.content, + source: preprocessOptions.data ? `${preprocessOptions.data} ${os.EOL} ${source}` : source, filename, id: scopeId, map: style.map, @@ -177,11 +184,7 @@ export class SFCCompiler { postcssPlugins, postcssOptions: this.style.postcssOptions, preprocessLang: style.lang, - preprocessOptions: - (style.lang && - this.style.preprocessOptions && - this.style.preprocessOptions[style.lang]) || - {}, + preprocessOptions, trim: this.style.trim }) From de6c19f7afa5fb81311a3a9b7b0af1db63a47580 Mon Sep 17 00:00:00 2001 From: Toni Martinez Date: Thu, 14 Jun 2018 10:17:08 +0200 Subject: [PATCH 2/3] Add test for data preprocessOptions in scss --- test/compile.spec.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/compile.spec.ts diff --git a/test/compile.spec.ts b/test/compile.spec.ts new file mode 100644 index 0000000..68f1f40 --- /dev/null +++ b/test/compile.spec.ts @@ -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')) +}) From 2574e0e63f20bb36d2fb1ba8b9eea4398a118e0c Mon Sep 17 00:00:00 2001 From: Rahul Kadyan Date: Mon, 25 Jun 2018 00:02:50 +0530 Subject: [PATCH 3/3] refactor: Use new line character --- src/compiler.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/compiler.ts b/src/compiler.ts index e4b13e4..ca11eb7 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -17,7 +17,6 @@ import postcssClean from './postcss-clean' import hash = require('hash-sum') import * as fs from 'fs' import * as path from 'path' -import os from'os' export interface TemplateOptions { compiler: VueTemplateCompiler @@ -176,7 +175,7 @@ export class SFCCompiler { {} const source = style.src ? this.read(style.src, filename) : style.content const result = compileStyle({ - source: preprocessOptions.data ? `${preprocessOptions.data} ${os.EOL} ${source}` : source, + source: preprocessOptions.data ? `${preprocessOptions.data}\n${source}` : source, filename, id: scopeId, map: style.map,