Blame view

node_modules/mpvue-loader/lib/utils/gen-id.js 529 Bytes
ce4c83ff   wxy   初始提交
1
2
3
4
5
6
7
8
9
10
11
12
13
  // utility for generating a uid for each component file
  // used in scoped CSS rewriting
  var path = require('path')
  var hash = require('hash-sum')
  var cache = Object.create(null)
  var sepRE = new RegExp(path.sep.replace('\\', '\\\\'), 'g')
  
  module.exports = function genId (file, context, key) {
    var contextPath = context.split(path.sep)
    var rootId = contextPath[contextPath.length - 1]
    file = rootId + '/' + path.relative(context, file).replace(sepRE, '/') + (key || '')
    return cache[file] || (cache[file] = hash(file))
  }