Skip to content

Commit

Permalink
fix: css modules extends error (#1452)
Browse files Browse the repository at this point in the history
fix #1449
  • Loading branch information
wmzy authored and yyx990803 committed Dec 14, 2018
1 parent 614b764 commit 082c6ea
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/codegen/styleInjection.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = function genStyleInjectionCode (
styleInjectionCode += `
cssModules[${name}] = ${locals}
Object.defineProperty(this, ${name}, {
configurable: true,
get: function () {
return cssModules[${name}]
}
Expand Down
17 changes: 17 additions & 0 deletions test/fixtures/css-modules-extend.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<style module>
.red {
color: #FF0000;
}
</style>

<script>
import CssModuleSimple from './css-modules-simple.vue'
export default {
extends: CssModuleSimple
}
</script>

<template>
<div :class="$style.red"></div>
</template>
40 changes: 40 additions & 0 deletions test/style.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,43 @@ test('CSS Modules', async () => {
/css-modules---red---\w{5}/
)
})

test('CSS Modules Extend', async () => {
return new Promise((resolve, reject) => {
const baseLoaders = [
'vue-style-loader',
{
loader: 'css-loader',
options: {
modules: true
}
}
]
mockBundleAndRun({
entry: 'css-modules-extend.vue',
modify: config => {
config.module.rules = [
{
test: /\.vue$/,
loader: 'vue-loader'
},
{
test: /\.css$/,
use: baseLoaders
}
]
}
}, ({ window, module, instance, jsdomError, bundleError }) => {
if (jsdomError) return reject(jsdomError)
if (bundleError) return reject(bundleError)

const vnode = mockRender(module)
expect(vnode.data.class).toBe(instance.$style.red)

const style = window.document.querySelectorAll('style')[1].textContent
expect(style).toContain(`.${instance.$style.red} {\n color: #FF0000;\n}`)

resolve()
})
})
})

0 comments on commit 082c6ea

Please sign in to comment.