From 74b93f736d07794bbb1b7a771a428f69a382ce68 Mon Sep 17 00:00:00 2001 From: Andy <33747619+VICTORYGS@users.noreply.github.com> Date: Fri, 26 Aug 2022 09:09:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?vue=E6=96=87=E4=BB=B6=20id=20hash=20?= =?UTF-8?q?=E7=AE=97=E6=B3=95=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 改成计数标记id,之后转化为36进制缩短id字符长度 --- src/index.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index d7d43700e..55a12a832 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,8 +3,6 @@ import * as path from 'path' import * as qs from 'querystring' import * as loaderUtils from 'loader-utils' -import hash = require('hash-sum') - import { parse } from 'vue/compiler-sfc' import type { TemplateCompiler, @@ -42,6 +40,7 @@ export interface VueLoaderOptions { } let errorEmitted = false +let shortFilePathCache: Array = [] const exportHelperPath = JSON.stringify(require.resolve('./exportHelper')) @@ -113,12 +112,9 @@ export default function loader( const rawShortFilePath = path .relative(rootContext || process.cwd(), filename) .replace(/^(\.\.[\/\\])+/, '') - const shortFilePath = rawShortFilePath.replace(/\\/g, '/') - const id = hash( - isProduction - ? shortFilePath + '\n' + source.replace(/\r\n/g, '\n') - : shortFilePath - ) + const shortFilePath = rawShortFilePath.replace(/\\/g, '/'); + shortFilePathCache.includes(shortFilePath) || shortFilePathCache.push(shortFilePath); + const id = shortFilePathCache.indexOf(shortFilePath).toString(36); // if the query has a type field, this is a language block request // e.g. foo.vue?type=template&id=xxxxx From 7741e413ebd36c66e3a95cde23c96b6e27c6312f Mon Sep 17 00:00:00 2001 From: Andy <33747619+VICTORYGS@users.noreply.github.com> Date: Mon, 29 Aug 2022 10:23:18 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A4=8D=E7=94=A8=20shortFilePath=20?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 复用 shortFilePath 计算结果,避免重复计算 --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 55a12a832..2127bfe6a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -243,7 +243,7 @@ export default function loader( // from the devtools. propsToAttach.push([ `__file`, - JSON.stringify(rawShortFilePath.replace(/\\/g, '/')), + JSON.stringify(shortFilePath), ]) } else if (options.exposeFilename) { // Libraries can opt-in to expose their components' filenames in production builds.