Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vue文件id 算法修改 #1991

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/index.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -42,6 +40,7 @@ export interface VueLoaderOptions {
}

let errorEmitted = false
let shortFilePathCache: Array<string> = []

const exportHelperPath = JSON.stringify(require.resolve('./exportHelper'))

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -247,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.
Expand Down