优化
This commit is contained in:
+7
-2
@@ -15,14 +15,19 @@ const pathMapPlugin = () => ({
|
||||
const result = {}
|
||||
const walk = (directory) => {
|
||||
if (!fs.existsSync(directory)) return
|
||||
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
||||
const entries = fs.readdirSync(directory, { withFileTypes: true })
|
||||
.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0)
|
||||
for (const entry of entries) {
|
||||
const filename = path.join(directory, entry.name)
|
||||
if (entry.isDirectory()) {
|
||||
walk(filename)
|
||||
} else if (filename.endsWith('.vue')) {
|
||||
const source = fs.readFileSync(filename, 'utf8')
|
||||
const match = source.match(/defineOptions\s*\(\s*{[\s\S]*?name:\s*['"]([^'"]+)['"]/)
|
||||
if (match) result[`/src/${filename.replace(/^src\//, '')}`] = match[1]
|
||||
if (match) {
|
||||
const relativePath = path.relative('src', filename).split(path.sep).join('/')
|
||||
result[`/src/${relativePath}`] = match[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user