Created
July 30, 2016 22:26
-
-
Save tyler-dot-earth/c3028380653983de3f5d925e73944808 to your computer and use it in GitHub Desktop.
Custom loader to remove 'composes' from CSS modules. Created for testing because of this bug https://github.com/istarkov/babel-plugin-webpack-loaders/issues/97
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Custom webpack loader which simply removes any use of 'composes'. | |
// This is because this bug https://github.com/istarkov/babel-plugin-webpack-loaders/issues/97 | |
// causing issues with testing. | |
module.exports = function removeComposes(source) { | |
if (process.env.NODE_ENV === 'test') { | |
const hasComposes = source.indexOf('composes') > 0; | |
if (!hasComposes) return source; | |
var numOfOccurences = source.match(/composes/g).length; | |
var modifiedSource = source; | |
for (var i = 0; i < numOfOccurences; i++) { | |
var startIndex = modifiedSource.indexOf('composes'); | |
var endIndex = modifiedSource.indexOf('\n', startIndex); | |
var removableLength = (endIndex - startIndex); | |
var toRemove = modifiedSource.substr(startIndex, removableLength); | |
modifiedSource = modifiedSource.replace(toRemove, ''); | |
} | |
return modifiedSource; | |
} | |
return source; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment