Skip to content

Commit e5fea3a

Browse files
committed
generate module id from project root to ensure consistent hash regardless of project path (close #613)
1 parent a12a298 commit e5fea3a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/gen-id.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
// utility for generating a uid for each component file
22
// used in scoped CSS rewriting
3+
var path = require('path')
34
var hash = require('hash-sum')
45
var cache = Object.create(null)
56

6-
module.exports = function genId (file) {
7+
module.exports = function genId (file, context) {
8+
context = context || process.cwd()
9+
var contextPath = context.split(path.sep)
10+
var rootId = contextPath[contextPath.length - 1]
11+
file = rootId + '/' + path.relative(context, file)
712
return cache[file] || (cache[file] = hash(file))
813
}

lib/loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module.exports = function (content) {
6060

6161
var filePath = this.resourcePath
6262
var fileName = path.basename(filePath)
63-
var moduleId = 'data-v-' + genId(filePath)
63+
var moduleId = 'data-v-' + genId(filePath, this._compiler.context)
6464
var styleRewriter = styleRewriterPath + '?id=' + moduleId
6565

6666
var cssLoaderOptions = ''

0 commit comments

Comments
 (0)