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');
4
4
var Core = require ( 'css-modules-loader-core' ) ;
5
5
var FileSystemLoader = require ( 'css-modules-loader-core/lib/file-system-loader' ) ;
6
6
var 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
+ } ;
7
20
8
21
var cssExt = / \. c s s $ / ;
9
22
module . exports = function ( browserify , options ) {
@@ -31,6 +44,11 @@ module.exports = function (browserify, options) {
31
44
32
45
var plugin = require ( name ) ;
33
46
47
+ // custom scoped name generation
48
+ if ( name === 'postcss-modules-scope' ) {
49
+ options [ name ] . generateScopedName = createScopedNameFunc ( plugin ) ;
50
+ }
51
+
34
52
if ( name in options ) {
35
53
plugin = plugin ( options [ name ] ) ;
36
54
} else {
Original file line number Diff line number Diff line change 6
6
"dependencies" : {
7
7
"css-modules-loader-core" : " 0.0.10" ,
8
8
"object-assign" : " ^3.0.0" ,
9
+ "string-hash" : " ^1.1.0" ,
9
10
"through" : " ^2.3.7"
10
11
},
11
12
"devDependencies" : {},
You can’t perform that action at this time.
0 commit comments