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

Commit

Permalink
feat: style-compiler should process one style block at a time
Browse files Browse the repository at this point in the history
To keep API akin to template-compiler, style style-compiler should
process one style block at a time.
  • Loading branch information
znck committed Oct 9, 2017
1 parent fef6fdd commit e6fa1ba
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ declare module VueComponentCompiler {
* @param styles List of styles to process.
* @param file SFC file path
*/
export function compileStyles(styles: Array<StyleCompilerSource>, file: string, config: StyleCompilerConfig): Promise<Array<StyleCompilerOutput>>
export function compileStyle(style: StyleCompilerSource, file: string, config: StyleCompilerConfig): Promise<Array<StyleCompilerOutput>>

/**
* Compile template to render functions
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
parse: require('./parser'),
compileStyles: require('./style-compiler'),
compileStyle: require('./style-compiler'),
compileTemplate: require('./template-compiler'),
assemble: require('./assemble'),
generateScopeId: require('./gen-id')
Expand Down
24 changes: 9 additions & 15 deletions src/style-compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ const defaults = require('lodash.defaultsdeep')
const trim = require('./plugins/trim')
const scopeId = require('./plugins/scope-id')

function compileStyle (style, filename, config) {
module.exports = function compileStyle (style, filename, config) {
config = defaults(config, {
async: false,
needMap: true,
plugins: [],
options: {},
onWarn: message => console.warn(message)
})

const plugins = [trim].concat(config.plugins)
const options = Object.assign({
to: filename,
Expand Down Expand Up @@ -48,17 +56,3 @@ function compileStyle (style, filename, config) {

return (config.async) ? output.then(prepare) : prepare(output)
}

module.exports = function compileStyles (styles, filename, config) {
config = defaults(config, {
async: false,
needMap: true,
plugins: [],
options: {},
onWarn: message => console.warn(message)
})

const results = styles.map(style => compileStyle(style, filename, config))

return config.async ? Promise.all(results) : results
}
4 changes: 2 additions & 2 deletions test/style-compiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ test('should rewrite scoped style', () => {
scoped: true
}
}
const compiled = compiler([style], 'foo.vue', { scopeId: 'xxx', needMap: false })
expect(compiled[0].code.indexOf('.foo[xxx]')).toBeGreaterThan(-1)
const compiled = compiler(style, 'foo.vue', { scopeId: 'xxx', needMap: false })
expect(compiled.code.indexOf('.foo[xxx]')).toBeGreaterThan(-1)
})

0 comments on commit e6fa1ba

Please sign in to comment.