diff --git a/lib/style-rewriter.js b/lib/style-rewriter.js index c631857..1195799 100644 --- a/lib/style-rewriter.js +++ b/lib/style-rewriter.js @@ -40,7 +40,7 @@ var addId = postcss.plugin('add-id', function () { */ module.exports = function (id, css, scoped, options) { - var key = id + '!!' + css + var key = id + '!!' + scoped + '!!' + css var val = cache.get(key) if (val) { return Promise.resolve(val) @@ -56,9 +56,16 @@ module.exports = function (id, css, scoped, options) { } // scoped css rewrite - if (scoped) { + // make sure the addId plugin is only pushed once + if (scoped && plugins.indexOf(addId) === -1) { plugins.push(addId) } + + // remove the addId plugin if the style block is not scoped + if (!scoped && plugins.indexOf(addId) !== -1) { + plugins.splice(plugins.indexOf(addId), 1) + } + // minification if (process.env.NODE_ENV === 'production') { plugins.push(require('cssnano')(assign({