From e1847c2526e52cb57c7326a3baac15182d6c1c0c Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Tue, 12 Jul 2022 15:02:41 +0800 Subject: [PATCH] fix(h5): Make sure components and apis are imported in the same order when tree shaking (#3611) --- .../packages/webpack-optimize-plugin/api.js | 11 +++++++---- .../packages/webpack-optimize-plugin/component.js | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/vue-cli-plugin-uni-optimize/packages/webpack-optimize-plugin/api.js b/packages/vue-cli-plugin-uni-optimize/packages/webpack-optimize-plugin/api.js index 407a0de7a..ff4142bb0 100644 --- a/packages/vue-cli-plugin-uni-optimize/packages/webpack-optimize-plugin/api.js +++ b/packages/vue-cli-plugin-uni-optimize/packages/webpack-optimize-plugin/api.js @@ -102,7 +102,8 @@ const isAppComponents = filepath => { const isCoreComponents = filepath => { return path.extname(filepath) === '.vue' && - (filepath.indexOf('/core/view/components/') === 0 || filepath.indexOf('/platforms/' + process.env.UNI_PLATFORM + '/view/components/') === 0) + (filepath.indexOf('/core/view/components/') === 0 || filepath.indexOf('/platforms/' + process.env.UNI_PLATFORM + + '/view/components/') === 0) } const isAppMixins = filepath => { @@ -149,8 +150,10 @@ function parseDeps (apis, manifest) { }, { test: isApiSubscribe, paths: apiSubscribePaths - }] - for (const name of apis.values()) { + }] + // 固定顺序,避免因顺序的变化导致内容变化,从而生成不同的 hash 文件名 + const apiNames = [...apis].sort() + for (const name of apiNames) { const options = manifest[name] if (Array.isArray(options)) { apiPaths[name] = options[0] @@ -241,4 +244,4 @@ module.exports = function updateApis (apis = new Set(), userApis = new Set()) { updateCoreComponents(coreComponentsPaths) updateAppMixins(appMixinsPaths) updateSystemRoutes(systemRoutesPaths) -} +} diff --git a/packages/vue-cli-plugin-uni-optimize/packages/webpack-optimize-plugin/component.js b/packages/vue-cli-plugin-uni-optimize/packages/webpack-optimize-plugin/component.js index 10446ced6..b3e5940a3 100644 --- a/packages/vue-cli-plugin-uni-optimize/packages/webpack-optimize-plugin/component.js +++ b/packages/vue-cli-plugin-uni-optimize/packages/webpack-optimize-plugin/component.js @@ -25,7 +25,7 @@ module.exports = function updateComponents (tags) { autoloadTags.other[tagName].forEach(tag => tags.add(tag)) } }) - tags = [...tags] + tags = [...tags].sort() // 固定顺序,避免因顺序的变化导致内容变化,从而生成不同的 hash 文件名 const importsStr = tags.map(tagName => { if (platformTags.indexOf(tagName) !== -1) { return `import ${capitalize(camelize(tagName))} from 'uni-platform/view/components/${tagName}'` -- GitLab