Skip to content
This repository was archived by the owner on Dec 26, 2018. It is now read-only.

Commit f25fb22

Browse files
danieldiekmeieryyx990803
authored andcommitted
Fix errors with scoped modules (#154)
1 parent 620e90e commit f25fb22

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/style-rewriter.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var addId = postcss.plugin('add-id', function () {
4040
*/
4141

4242
module.exports = function (id, css, scoped, options) {
43-
var key = id + '!!' + css
43+
var key = id + '!!' + scoped + '!!' + css
4444
var val = cache.get(key)
4545
if (val) {
4646
return Promise.resolve(val)
@@ -56,9 +56,16 @@ module.exports = function (id, css, scoped, options) {
5656
}
5757

5858
// scoped css rewrite
59-
if (scoped) {
59+
// make sure the addId plugin is only pushed once
60+
if (scoped && plugins.indexOf(addId) === -1) {
6061
plugins.push(addId)
6162
}
63+
64+
// remove the addId plugin if the style block is not scoped
65+
if (!scoped && plugins.indexOf(addId) !== -1) {
66+
plugins.splice(plugins.indexOf(addId), 1)
67+
}
68+
6269
// minification
6370
if (process.env.NODE_ENV === 'production') {
6471
plugins.push(require('cssnano')(assign({

0 commit comments

Comments
 (0)