File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
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 createScopedNameFunc ( 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,12 @@ module.exports = function (browserify, options) {
3144
3245 var plugin = require ( require . resolve ( name ) ) ;
3346
47+ // custom scoped name generation
48+ if ( name === 'postcss-modules-scope' ) {
49+ options [ name ] = options [ name ] || { } ;
50+ options [ name ] . generateScopedName = createScopedNameFunc ( plugin ) ;
51+ }
52+
3453 if ( name in options ) {
3554 plugin = plugin ( options [ name ] ) ;
3655 } else {
Original file line number Diff line number Diff line change 44 "description" : " A browserify transform to load CSS Modules" ,
55 "main" : " index.js" ,
66 "dependencies" : {
7- "css-modules-loader-core" : " 0.0.10 " ,
7+ "css-modules-loader-core" : " 0.0.11 " ,
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