Skip to content

Commit 59b94e5

Browse files
committed
perf(generator): use regex to match domain
1 parent c3a2c90 commit 59b94e5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

packages/generator/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ function addConfig(module: string, base: string) {
3535

3636
const url = new URL(base)
3737
const hostname = url.hostname
38-
const parts = hostname.split('.')
39-
const mainDomain = parts.slice(-3).join('.') // 拿到根域名
40-
// 检查一下 hostnames 里面有没有这个根域名,没有的话就加进去
38+
const regex = /(?:https?:\/\/)?(?:www\.)?([^\/]+)\/?.*/
39+
const mainDomain = hostname.match(regex)?.[1] || hostname
40+
// 检查一下 hostnames 里面有没有这个域名,没有的话就加进去
4141
if (!hostnames.includes(`${mainDomain}`))
4242
hostnames.push(`${mainDomain}`)
4343

0 commit comments

Comments
 (0)