Skip to content

Commit 8f72df8

Browse files
rchaser53eddyerburgh
authored andcommitted
suppress the error when using sass, postcss, less module (#70)
1 parent 87d1049 commit 8f72df8

File tree

7 files changed

+71
-5
lines changed

7 files changed

+71
-5
lines changed

lib/process.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,10 @@ module.exports = function (src, filePath) {
107107

108108
const styleStr = parts.styles.map(ast => {
109109
if (!module) return
110-
if (/^scss|sass|less|pcss|postcss/.test(ast.lang)) {
111-
return false
112-
}
113-
110+
const styleObj = (/^scss|sass|less|pcss|postcss/.test(ast.lang))
111+
? {}
112+
: processStyle(ast, filePath)
114113
const moduleName = ast.module === true ? '$style' : ast.module
115-
const styleObj = processStyle(ast, filePath)
116114

117115
return '\n this[\'' + moduleName + '\'] = ' + JSON.stringify(styleObj)
118116
}).filter(_ => _)

test/less.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { shallow } from 'vue-test-utils'
22
import Less from './resources/Less.vue'
3+
import LessModule from './resources/LessModule.vue'
34

45
describe('processes .vue file with Less style', () => {
56
it('does not error on less', () => {
67
const wrapper = shallow(Less)
78
expect(wrapper.classes()).toContain('testLess')
89
})
10+
11+
it('does not error on less module', () => {
12+
expect(() => shallow(LessModule)).not.toThrow()
13+
})
914
})

test/postcss.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { shallow } from 'vue-test-utils'
22
import PostCss from './resources/PostCss.vue'
3+
import PostCssModule from './resources/PostCssModule.vue'
34

45
describe('processes .vue file with PostCSS style', () => {
56
it('does not error on pcss/postcss', () => {
67
const wrapper = shallow(PostCss)
78
expect(wrapper.classes()).toContain('testPcss')
89
})
10+
11+
it('does not error on pcss/postcss module', () => {
12+
expect(() => shallow(PostCssModule)).not.toThrow()
13+
})
914
})

test/resources/LessModule.vue

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<div :class="$style.testLess"></div>
3+
</template>
4+
5+
<style module lang="less">
6+
@import "./styles/transitions";
7+
8+
.testLess {
9+
background-color: red;
10+
}
11+
</style>
12+
13+
<style module lang="less">
14+
@primary-color: #333;
15+
</style>

test/resources/PostCssModule.vue

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<template>
2+
<div :class="$style.testPcss"></div>
3+
</template>
4+
5+
<style module lang="postcss">
6+
@import "./styles/transitions";
7+
8+
.testPcss {
9+
background-color: purple;
10+
}
11+
</style>
12+
13+
<style module lang="pcss">
14+
/* This syntax is for postcss-custom-properties */
15+
--primary-color: green;
16+
17+
/* This syntax is for postcss-nesting, but invalid as Pure CSS */
18+
body {
19+
@media screen {
20+
background-color: grey;
21+
}
22+
}
23+
</style>

test/resources/SassModule.vue

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<div :class="$style.testA"></div>
3+
</template>
4+
5+
<style module lang="scss">
6+
@import "./styles/transitions";
7+
8+
.testA {
9+
background-color: red;
10+
}
11+
</style>
12+
13+
<style module lang="sass">
14+
$primary-color: #333
15+
</style>

test/scss.spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { shallow } from 'vue-test-utils'
22
import Sass from './resources/Sass.vue'
3+
import SassModule from './resources/SassModule.vue'
34

45
describe('processes .vue file with Stylus style', () => {
56
it('does not error on scss or sass', () => {
67
const wrapper = shallow(Sass)
78
expect(wrapper.classes()).toContain('testA')
89
})
10+
11+
it('does not error on scss/sass module', () => {
12+
expect(() => shallow(SassModule)).not.toThrow()
13+
})
914
})

0 commit comments

Comments
 (0)