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

Fix errors with scoped modules #154

Merged
merged 1 commit into from
Dec 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/style-rewriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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({
Expand Down