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