File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,19 @@ var through = require('through');
44var Core = require ( 'css-modules-loader-core' ) ;
55var FileSystemLoader = require ( 'css-modules-loader-core/lib/file-system-loader' ) ;
66var assign = require ( 'object-assign' ) ;
7+ var stringHash = require ( 'string-hash' ) ;
8+
9+ /*
10+ Custom `generateScopedName` function for `postcss-modules-scope`.
11+ Appends a hash of the css source.
12+ */
13+ function createNameFunc ( plugin ) {
14+ var orig = plugin . generateScopedName ;
15+ return function ( name , path , css ) {
16+ var hash = stringHash ( css ) . toString ( 36 ) . substr ( 0 , 5 ) ;
17+ return orig . apply ( plugin , arguments ) + '___' + hash ;
18+ }
19+ } ;
720
821var cssExt = / \. c s s $ / ;
922module . exports = function ( browserify , options ) {
@@ -31,6 +44,11 @@ module.exports = function (browserify, options) {
3144
3245 var plugin = require ( name ) ;
3346
47+ // custom scoped name generation
48+ if ( name === 'postcss-modules-scope' ) {
49+ options [ name ] . generateScopedName = createScopedNameFunc ( plugin ) ;
50+ }
51+
3452 if ( name in options ) {
3553 plugin = plugin ( options [ name ] ) ;
3654 } else {
Original file line number Diff line number Diff line change 66 "dependencies" : {
77 "css-modules-loader-core" : " 0.0.10" ,
88 "object-assign" : " ^3.0.0" ,
9+ "string-hash" : " ^1.1.0" ,
910 "through" : " ^2.3.7"
1011 },
1112 "devDependencies" : {},
You can’t perform that action at this time.
0 commit comments