Skip to content

Commit a3da7fc

Browse files
committed
fix: less stylesheets as global resources
1 parent 411d1e8 commit a3da7fc

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

lib/process-style.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,25 @@ const getCustomTransformer = require('./utils').getCustomTransformer
77
const logResultErrors = require('./utils').logResultErrors
88
const loadSrc = require('./utils').loadSrc
99

10-
function getGlobalResources(resources, lang, filePath) {
10+
function getGlobalResources(resources, lang) {
1111
let globalResources = ''
1212
if (resources && resources[lang]) {
1313
globalResources = resources[lang]
1414
.map(resource => {
15-
const relativePath = path.relative(
16-
path.dirname(filePath),
17-
path.resolve(process.cwd(), resource)
18-
)
19-
return `${getImportLine(lang, relativePath)}\n`
15+
const absolutePath = path.resolve(process.cwd(), resource)
16+
return `${getImportLine(lang, absolutePath)}\n`
2017
})
2118
.join('')
2219
}
2320
return globalResources
2421
}
2522

2623
function getImportLine(lang, filePath) {
27-
const placeholder = '__PATH__'
28-
const formats = {
29-
default: `@import "${placeholder}";`,
30-
sass: `@import "${placeholder}"`
24+
const importLines = {
25+
default: `@import "${filePath}";`,
26+
sass: `@import "${filePath}"`
3127
}
32-
return (formats[lang] || formats.default).replace(placeholder, filePath)
28+
return importLines[lang] || importLines.default
3329
}
3430

3531
function extractClassMap(cssCode) {
@@ -80,7 +76,7 @@ module.exports = function processStyle(stylePart, filePath, config = {}) {
8076
}
8177

8278
let content =
83-
getGlobalResources(vueJestConfig.resources, stylePart.lang, filePath) +
79+
getGlobalResources(vueJestConfig.resources, stylePart.lang) +
8480
stylePart.content
8581

8682
const transformer =

0 commit comments

Comments
 (0)