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

Commit f8110f6

Browse files
authored
Fix #91, Process scoped styles and css modules when auto styles is turned off (#94)
* Add failing tests for #91 * Process scoped css & css modules when auto styles set to false
1 parent 1ccc9ad commit f8110f6

5 files changed

+63
-13
lines changed

src/vueTransform.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ async function processTemplate (source, id, content, options, nodes, modules) {
5454
const extras = { modules, id, lang: source.attrs.lang }
5555
const code = deIndent(source.code)
5656
const template = await (
57-
options.disableCssModuleStaticReplacement !== true
58-
? templateProcessor(code, extras, options)
59-
: code
57+
options.disableCssModuleStaticReplacement !== true
58+
? templateProcessor(code, extras, options)
59+
: code
6060
)
6161

6262
if (!options.compileTemplate) {
@@ -134,10 +134,10 @@ async function processStyle (styles, id, content, options) {
134134
map: map,
135135
lang: style.attrs.lang || 'css',
136136
module: 'module' in style.attrs ? style.attrs.module || true : false,
137-
scoped: 'scoped' in style.attrs ? style.attrs.scoped || true : false
137+
scoped: 'scoped' in style.attrs
138138
}
139139

140-
outputs.push(options.autoStyles ? await compile(output, options) : output)
140+
outputs.push(options.autoStyles || output.scoped || output.module ? await compile(output, options) : output)
141141
}
142142

143143
return outputs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.scoped-css-with-no-auto-style__test2 {
2+
color: red;
3+
}
4+
5+
6+
7+
8+
9+
10+
11+
12+
13+
14+
.test[data-v-0cd69708] {
15+
color: red;
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var scopedCssWithNoAutoStyle = { template: "<div class=\"test scoped-css-with-no-auto-style__test2\">Foo</div>",_scopeId: 'data-v-0cd69708',cssModules: {"test2":"scoped-css-with-no-auto-style__test2"},};
2+
3+
export default scopedCssWithNoAutoStyle;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<template>
2+
<div class="test test2">Foo</div>
3+
</template>
4+
5+
<script lang="babel">
6+
export default {}
7+
</script>
8+
9+
<style lang="css" scoped>
10+
.test {
11+
color: red;
12+
}
13+
</style>
14+
15+
<style lang="css" module>
16+
.test2 {
17+
color: red;
18+
}
19+
</style>

test/test.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,32 @@ function test(name) {
3333
modules: {
3434
generateScopedName: '[name]__[local]'
3535
},
36-
compileTemplate: [
37-
'compileTemplate',
38-
'compileTemplateLocalComponent',
39-
'slot',
40-
'table',
41-
'table-n-slot'
42-
].indexOf(name) > -1
36+
compileTemplate: [
37+
'compileTemplate',
38+
'compileTemplateLocalComponent',
39+
'slot',
40+
'table',
41+
'table-n-slot'
42+
].indexOf(name) > -1,
43+
autoStyles: ['scoped-css-with-no-auto-style'].indexOf(name) < 0
4344
})]
4445
}).then(function (bundle) {
4546
var result = bundle.generate({ format: 'es' })
4647
var code = result.code
4748
assert.equal(code.trim(), expected.trim(), 'should compile code correctly')
4849

4950
// Check css output
50-
if (['style', 'css-modules', 'css-modules-static', 'scoped-css', 'scss', 'pug', 'less', 'stylus'].indexOf(name) > -1) {
51+
if ([
52+
'style',
53+
'css-modules',
54+
'css-modules-static',
55+
'scoped-css',
56+
'scoped-css-with-no-auto-style',
57+
'scss',
58+
'pug',
59+
'less',
60+
'stylus'
61+
].indexOf(name) > -1) {
5162
var css = read('expects/' + name + '.css')
5263
assert.equal(css.trim(), actualCss.trim(), 'should output style tag content')
5364
} else if (['no-css-extract'].indexOf(name) > -1) {
@@ -96,3 +107,4 @@ describe('styleToImports', function () {
96107
})
97108
})
98109
})
110+

0 commit comments

Comments
 (0)