@@ -4,32 +4,31 @@ const sass = require('node-sass')
4
4
const cwd = process . cwd ( )
5
5
6
6
module . exports = ( content , dir , config ) => {
7
-
8
7
const getRelativeImportPath = ( oldImportPath , absoluteImportPath ) => ( / ^ \~ / . test ( oldImportPath ) )
9
8
? oldImportPath
10
- : path . relative ( cwd , absoluteImportPath ) ;
9
+ : path . relative ( cwd , absoluteImportPath )
11
10
12
- const scssResources = ( ! config . resources || ! config . resources . scss )
13
- ? ''
14
- : config . resources . scss
15
- . map ( scssResource => path . resolve ( cwd , scssResource ) )
16
- . filter ( scssResourcePath => fs . existsSync ( scssResourcePath ) )
17
- . map ( scssResourcePath => fs . readFileSync ( scssResourcePath ) . toString ( )
18
- . replace ( / @ i m p o r t \s + (?: ' ( [ ^ ' ] + ) ' | " ( [ ^ " ] + ) " | ( [ ^ \s ; ] + ) ) / g, ( entire , single , double , unquoted ) => {
19
- var oldImportPath = single || double || unquoted ;
20
- var absoluteImportPath = path . join ( path . dirname ( scssResourcePath ) , oldImportPath ) ;
21
- var relImportPath = getRelativeImportPath ( oldImportPath , absoluteImportPath ) ;
22
- var newImportPath = relImportPath . split ( path . sep ) . join ( '/' ) ;
23
- var lastCharacter = entire [ entire . length - 1 ] ;
24
- var quote = lastCharacter === "'" || lastCharacter === '"' ? lastCharacter : '' ;
25
- return '@import ' + quote + newImportPath + quote ;
26
- } )
27
- )
28
- . join ( '\n' )
11
+ let scssResources = ''
12
+ if ( config . resources && config . resources . scss ) {
13
+ scssResources = config . resources . scss
14
+ . map ( scssResource => path . resolve ( cwd , scssResource ) )
15
+ . filter ( scssResourcePath => fs . existsSync ( scssResourcePath ) )
16
+ . map ( scssResourcePath => fs . readFileSync ( scssResourcePath ) . toString ( )
17
+ . replace ( / @ i m p o r t \s + (?: ' ( [ ^ ' ] + ) ' | " ( [ ^ " ] + ) " | ( [ ^ \s ; ] + ) ) / g, ( entire , single , double , unquoted ) => {
18
+ const oldImportPath = single || double || unquoted
19
+ const absoluteImportPath = path . join ( path . dirname ( scssResourcePath ) , oldImportPath )
20
+ const relImportPath = getRelativeImportPath ( oldImportPath , absoluteImportPath )
21
+ const newImportPath = relImportPath . split ( path . sep ) . join ( '/' )
22
+ const lastCharacter = entire [ entire . length - 1 ]
23
+ const quote = lastCharacter === "'" || lastCharacter === '"' ? lastCharacter : ''
24
+ return '@import ' + quote + newImportPath + quote
25
+ } )
26
+ )
27
+ . join ( '\n' )
28
+ }
29
29
30
30
return sass . renderSync ( {
31
31
data : scssResources + content ,
32
32
outputStyle : 'compressed'
33
33
} ) . css . toString ( )
34
-
35
- }
34
+ }
0 commit comments