packages/veui-loader/src/index.js
function patchType (content, type, peerPaths) {
  let normalizedPaths = peerPaths.map(path => slash(normalize(path)))
  switch (type) {
    case 'script':
      let scriptImports = normalizedPaths.map(path => `import '${path}'\n`)
      content = content.replace(RE_SCRIPT, match => {
        return `${match}\n${scriptImports.join('')}`
      })
      break
    case 'style':
      let styleImports = normalizedPaths.map(path => {
        let langStr = ''
        let ext = getExtname(path)
        if (ext !== 'css') {
          langStr = `lang="${ext}" `
        }
        return `<style ${langStr}src="${path}"></style>\n`
      })
      content += styleImports.join('')
      break
    default:
      break
  }

  return content
}
function patchType (content, type, peerPaths) {
  let normalizedPaths = peerPaths.map(path => slash(normalize(path)))
  switch (type) {
    case 'script':
      let scriptImports = normalizedPaths.map(path => `import '${path}'\n`)
      content = content.replace(RE_SCRIPT, match => {
        return `${match}\n${scriptImports.join('')}`
      })
      break
    case 'style':
      let styleImports = normalizedPaths.map(path => {
        let langStr = ''
        let ext = getExtname(path)
        if (ext !== 'css') {
          langStr = `lang="${ext}" `
        }
        return `<style ${langStr}src="${path}"></style>\n`
      })
      content += styleImports.join('')
      break
    default:
      break
  }

  return content
}
function patchType ( content , type , peerPaths ) { let normalizedPaths = peerPaths . map ( path => slash ( normalize ( path ) ) ) switch ( type ) { case 'script' : let scriptImports = normalizedPaths . map ( path => ` ${ path } \n ` ) content = content . replace ( RE_SCRIPT , match => { return ` ${ match } \n ${ scriptImports . join ( '' ) } ` } ) break case 'style' : let styleImports = normalizedPaths . map ( path => { let langStr = '' let ext = getExtname ( path ) if ( ext !== 'css' ) { langStr = ` ${ ext } ` } return ` ${ langStr } ${ path } \n ` } ) content += styleImports . join ( '' ) break default : break } return content }
Patch file content according to a given type.
@param {string} content Original content
@param {string} type Peer type, can be `script` or `style`
@param {Array<string>} peerPaths Peer module paths
@returns {string} The patched content
Patch file content according to a given type .