Skip to content
This repository was archived by the owner on Aug 16, 2022. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e6fa1ba

Browse files
committedOct 9, 2017
feat: style-compiler should process one style block at a time
To keep API akin to template-compiler, style style-compiler should process one style block at a time.
1 parent fef6fdd commit e6fa1ba

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed
 

‎index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ declare module VueComponentCompiler {
1313
* @param styles List of styles to process.
1414
* @param file SFC file path
1515
*/
16-
export function compileStyles(styles: Array<StyleCompilerSource>, file: string, config: StyleCompilerConfig): Promise<Array<StyleCompilerOutput>>
16+
export function compileStyle(style: StyleCompilerSource, file: string, config: StyleCompilerConfig): Promise<Array<StyleCompilerOutput>>
1717

1818
/**
1919
* Compile template to render functions

‎src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
parse: require('./parser'),
3-
compileStyles: require('./style-compiler'),
3+
compileStyle: require('./style-compiler'),
44
compileTemplate: require('./template-compiler'),
55
assemble: require('./assemble'),
66
generateScopeId: require('./gen-id')

‎src/style-compiler/index.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ const defaults = require('lodash.defaultsdeep')
44
const trim = require('./plugins/trim')
55
const scopeId = require('./plugins/scope-id')
66

7-
function compileStyle (style, filename, config) {
7+
module.exports = function compileStyle (style, filename, config) {
8+
config = defaults(config, {
9+
async: false,
10+
needMap: true,
11+
plugins: [],
12+
options: {},
13+
onWarn: message => console.warn(message)
14+
})
15+
816
const plugins = [trim].concat(config.plugins)
917
const options = Object.assign({
1018
to: filename,
@@ -48,17 +56,3 @@ function compileStyle (style, filename, config) {
4856

4957
return (config.async) ? output.then(prepare) : prepare(output)
5058
}
51-
52-
module.exports = function compileStyles (styles, filename, config) {
53-
config = defaults(config, {
54-
async: false,
55-
needMap: true,
56-
plugins: [],
57-
options: {},
58-
onWarn: message => console.warn(message)
59-
})
60-
61-
const results = styles.map(style => compileStyle(style, filename, config))
62-
63-
return config.async ? Promise.all(results) : results
64-
}

‎test/style-compiler.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ test('should rewrite scoped style', () => {
77
scoped: true
88
}
99
}
10-
const compiled = compiler([style], 'foo.vue', { scopeId: 'xxx', needMap: false })
11-
expect(compiled[0].code.indexOf('.foo[xxx]')).toBeGreaterThan(-1)
10+
const compiled = compiler(style, 'foo.vue', { scopeId: 'xxx', needMap: false })
11+
expect(compiled.code.indexOf('.foo[xxx]')).toBeGreaterThan(-1)
1212
})

0 commit comments

Comments
 (0)
This repository has been archived.