@@ -2,7 +2,9 @@ const assign = require('lodash').assign;
22const attachHook = require ( './attachHook' ) ;
33const dirname = require ( 'path' ) . dirname ;
44const genericNames = require ( 'generic-names' ) ;
5+ const globToRegex = require ( 'glob-to-regexp' ) ;
56const identity = require ( 'lodash' ) . identity ;
7+ const negate = require ( 'lodash' ) . negate ;
68const readFileSync = require ( 'fs' ) . readFileSync ;
79const relative = require ( 'path' ) . relative ;
810const resolve = require ( 'path' ) . resolve ;
@@ -15,8 +17,25 @@ const ExtractImports = require('postcss-modules-extract-imports');
1517const Scope = require ( 'postcss-modules-scope' ) ;
1618const Parser = require ( 'postcss-modules-parser' ) ;
1719
20+ /**
21+ * @param {function|regex|string } ignore glob, regex or function
22+ * @return {function }
23+ */
24+ function buildExceptionChecker ( ignore ) {
25+ if ( ignore instanceof RegExp ) {
26+ return filepath => ignore . test ( filepath ) ;
27+ }
28+
29+ if ( typeof ignore === 'string' ) {
30+ return filepath => globToRegex ( ignore ) . test ( filepath ) ;
31+ }
32+
33+ return ignore || negate ( identity ) ;
34+ }
35+
1836module . exports = function setupHook ( {
1937 extensions = '.css' ,
38+ ignore,
2039 preprocessCss = identity ,
2140 processCss,
2241 to,
@@ -96,5 +115,7 @@ module.exports = function setupHook({
96115 return tokens ;
97116 } ;
98117
99- attachHook ( filename => fetch ( filename , filename ) , '.css' , ( ) => false ) ;
118+ const isException = buildExceptionChecker ( ignore ) ;
119+
120+ attachHook ( filename => fetch ( filename , filename ) , '.css' , isException ) ;
100121} ;
0 commit comments