diff --git a/packages/uni-template-compiler/lib/index.js b/packages/uni-template-compiler/lib/index.js index 904536958326df78af65fd78bd9bd5c483637be8..ff13c3db73f05cee8ba2fff9694fd4dc86b3959d 100644 --- a/packages/uni-template-compiler/lib/index.js +++ b/packages/uni-template-compiler/lib/index.js @@ -1,5 +1,5 @@ const path = require('path') - +const hash = require('hash-sum') const parser = require('@babel/parser') const { @@ -95,6 +95,11 @@ module.exports = { options.mp.scopeId = options.scopeId options.mp.resourcePath = options.resourcePath + if (options.resourcePath) { + options.mp.hashId = hash(options.resourcePath) + } else { + options.mp.hashId = '' + } options.mp.globalUsingComponents = options.globalUsingComponents || Object.create(null) diff --git a/packages/uni-template-compiler/lib/script/traverse/visitor.js b/packages/uni-template-compiler/lib/script/traverse/visitor.js index 0dd5124452fb2beada2a8a691ece782c4d244477..f7bbb7c12beb23a36be7bec33055d85591cb14a2 100644 --- a/packages/uni-template-compiler/lib/script/traverse/visitor.js +++ b/packages/uni-template-compiler/lib/script/traverse/visitor.js @@ -58,7 +58,8 @@ function addVueId (path, state) { if (!state.options.hasOwnProperty('$vueId')) { state.options.$vueId = 1 } - const vueId = String(state.options.$vueId++) + const hashId = state.options.hashId + const vueId = String((hashId ? (hashId + '-') : '') + (state.options.$vueId++)) let value