3
3
import './guard' ;
4
4
import hook from './hook' ;
5
5
import postcss from 'postcss' ;
6
- import { basename , dirname , join , resolve } from 'path' ;
6
+ import { basename , dirname , join , relative , resolve } from 'path' ;
7
7
import { readFileSync } from 'fs' ;
8
8
9
9
import extractImports from 'postcss-modules-extract-imports' ;
@@ -12,6 +12,7 @@ import scope from 'postcss-modules-scope';
12
12
import parser from './parser' ;
13
13
14
14
let plugins = [ localByDefault , extractImports , scope ] ;
15
+ let rootDir ;
15
16
16
17
/**
17
18
* @param {string } sourceString The file content
@@ -32,7 +33,7 @@ function load(sourceString, sourcePath, trace, pathFetcher) {
32
33
}
33
34
34
35
hook ( filename => {
35
- const root = dirname ( filename ) ;
36
+ const root = rootDir || dirname ( filename ) ;
36
37
const sources = { } ;
37
38
const tokensByFile = { } ;
38
39
let importNr = 0 ;
@@ -59,7 +60,7 @@ hook(filename => {
59
60
return exportTokens ;
60
61
}
61
62
62
- return fetch ( basename ( filename ) , '/' ) ;
63
+ return fetch ( relative ( root , filename ) , '/' ) ;
63
64
} ) ;
64
65
65
66
/**
@@ -74,4 +75,8 @@ export default function configure(opts) {
74
75
plugins = Array . isArray ( customPlugins )
75
76
? customPlugins
76
77
: [ localByDefault , extractImports , scope ] ;
78
+
79
+ if ( opts . root && typeof opts . root === 'string' ) {
80
+ rootDir = opts . root ;
81
+ }
77
82
}
0 commit comments