feature: 放弃自己研发的代码定位功能,集成vite官方的devtool工具

This commit is contained in:
pixelMax(奇淼
2024-07-26 13:37:59 +08:00
parent 055198ccd5
commit 5c7d121e67
6 changed files with 4 additions and 138 deletions

View File

@@ -1,43 +0,0 @@
const child_process = require('child_process')
export default function GvaPositionServer() {
return {
name: 'gva-position-server',
apply: 'serve',
configureServer(server) {
server.middlewares.use((req, _, next) => {
if (req._parsedUrl.pathname === '/gvaPositionCode') {
const path =
req._parsedUrl.query && req._parsedUrl.query.split('=')[1]
if (path && path !== 'null') {
if (process.env.VITE_EDITOR === 'webstorm') {
const lastColonIndex = path.lastIndexOf(':')
const linePath = path.substring(lastColonIndex + 1)
const filePath = path.substring(0, lastColonIndex)
const platform = os()
if (platform === 'win32') {
child_process.exec(
`webstorm64.exe --line ${linePath} ${filePath}`
)
} else {
child_process.exec(
`webstorm --line ${linePath} ${filePath}`
)
}
} else {
child_process.exec('code -r -g ' + path)
}
}
}
next()
})
},
}
}
function os() {
'use strict'
const os = require('os')
const platform = os.platform()
return platform
}

View File

@@ -1,51 +0,0 @@
export default function GvaPosition() {
return {
name: 'gva-position',
apply: 'serve',
transform(code, id) {
const index = id.lastIndexOf('.')
const ext = id.substr(index + 1)
if (ext.toLowerCase() === 'vue') {
return codeLineTrack(code, id)
}
},
}
}
const codeLineTrack = (code, id) => {
const lineList = code.split('\n')
const newList = []
lineList.forEach((item, index) => {
newList.push(addLineAttr(item, index + 1, id)) // 添加位置属性index+1为具体的代码行号
})
return newList.join('\n')
}
const addLineAttr = (lineStr, line, id) => {
if (!/^\s+</.test(lineStr)) {
return lineStr
}
const reg = /((((^(\s)+\<))|(^\<))[\w-]+)|(<\/template)/g
let leftTagList = lineStr.match(reg)
if (leftTagList) {
leftTagList = Array.from(new Set(leftTagList))
leftTagList.forEach((item) => {
const skip = [
'KeepAlive',
'template',
'keep-alive',
'transition',
'el-',
'El',
'router-view',
]
if (item && !skip.some((i) => item.indexOf(i) > -1)) {
const reg = new RegExp(`${item}`)
const location = `${item} code-location="${id}:${line}"`
lineStr = lineStr.replace(reg, location)
}
})
}
return lineStr
}