保誠-保戶業務員媒合平台
HelenHuang
2022-06-09 9bdb95c9e34cef640534e5e5a1e2225a80442000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const getVueJestConfig = require('./get-vue-jest-config')
const cssExtract = require('extract-from-css')
 
module.exports = function processStyle (stylePart, filePath, jestConfig = {}) {
  const vueJestConfig = getVueJestConfig(jestConfig)
 
  if (!stylePart || vueJestConfig.experimentalCSSCompile === false) {
    return {}
  }
 
  const processStyleByLang = lang => require('./compilers/' + lang + '-compiler')(stylePart.content, filePath, jestConfig)
 
  let cssCode = stylePart.content
  switch (stylePart.lang) {
    case 'styl':
    case 'stylus':
      cssCode = processStyleByLang('stylus')
      break
    case 'scss':
      cssCode = processStyleByLang('scss')
      break
    case 'sass':
      cssCode = processStyleByLang('sass')
      break
    case 'pcss':
    case 'postcss':
      cssCode = processStyleByLang('postcss')
      break
  }
 
  const cssNames = cssExtract.extractClasses(cssCode)
 
  const obj = {}
  for (let i = 0, l = cssNames.length; i < l; i++) {
    obj[cssNames[i]] = cssNames[i]
  }
 
  return obj
}