Skip to content

Commit a2878b9

Browse files
committed
support hashKey option (close vuejs#645)
1 parent b9efa33 commit a2878b9

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

lib/gen-id.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ var hash = require('hash-sum')
55
var cache = Object.create(null)
66
var sepRE = new RegExp(path.sep.replace('\\', '\\\\'), 'g')
77

8-
module.exports = function genId (file, context) {
8+
module.exports = function genId (file, context, key) {
99
var contextPath = context.split(path.sep)
1010
var rootId = contextPath[contextPath.length - 1]
11-
file = rootId + '/' + path.relative(context, file).replace(sepRE, '/')
11+
file = rootId + '/' + path.relative(context, file).replace(sepRE, '/') + (key || '')
1212
return cache[file] || (cache[file] = hash(file))
1313
}

lib/loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ module.exports = function (content) {
6262
var fileName = path.basename(filePath)
6363

6464
var context = (this._compiler && this._compiler.context) || this.options.context || process.cwd()
65-
var moduleId = 'data-v-' + genId(filePath, context)
65+
var moduleId = 'data-v-' + genId(filePath, context, options.hashKey)
6666

6767
var cssLoaderOptions = ''
6868
if (!isProduction && this.sourceMap && options.cssSourceMap !== false) {

test/test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,12 @@ describe('vue-loader', function () {
162162

163163
it('scoped style', done => {
164164
test({
165-
entry: './test/fixtures/scoped-css.vue'
165+
entry: './test/fixtures/scoped-css.vue',
166+
vue: {
167+
hashKey: 'foo'
168+
}
166169
}, (window, module) => {
167-
var id = 'data-v-' + hash('vue-loader/test/fixtures/scoped-css.vue')
170+
var id = 'data-v-' + hash('vue-loader/test/fixtures/scoped-css.vue' + 'foo')
168171
expect(module._scopeId).to.equal(id)
169172

170173
var vnode = mockRender(module, {

0 commit comments

Comments
 (0)