feat: support import img by alias

This commit is contained in:
Joel 2025-11-13 18:13:28 +08:00
parent 4637435e42
commit b3a4721815
4 changed files with 31 additions and 4 deletions

View File

@ -1,3 +1,21 @@
.bg {
background-color: red;
}
.bgImg {
background-repeat: no-repeat;
background-repeat: left center;
background-image: url(~@/app/components/develop/secret-key/assets/play.svg);
}
.bgCopied {
background-repeat: no-repeat;
background-repeat: left center;
background-image: url(../copied.svg);
}
.bgCopied2 {
background-repeat: no-repeat;
background-repeat: left center;
background-image: url(~@edition/copied.svg);
}

View File

@ -2,10 +2,15 @@
import type { FC } from 'react'
import React from 'react'
import s from '@edition/sub/sub-c.module.css'
import cn from '@/utils/classnames'
const Test: FC = () => {
return (
<div className={s.bg}>SaaS</div>
<>
<div className={cn(s.bgImg, 'pl-4')}>SaaS</div>
<div className={cn(s.bgCopied, 'pl-4')}>Copied</div>
<div className={cn(s.bgCopied2, 'pl-4')}>Import svg use alias</div>
</>
)
}
export default React.memo(Test)

View File

@ -106,7 +106,7 @@ const editionPaths = (() => {
walk(fullPath)
} else if (supportPostfixReg.test(file)) {
const relPath = path.relative(editionDir, fullPath)
const key = `@edition/${relPath.replace(/\\/g, '/')}`.replace(/\.(ts|tsx|css)$/, '')
const key = `@edition/${relPath.replace(/\\/g, '/')}`.replace(supportPostfixReg, '')
const fullPathWithoutPrefix = `./${fullPath.replace(supportPostfixReg, '')}`
result[key] = fullPathWithoutPrefix
if (key.endsWith('/index')) {
@ -124,7 +124,7 @@ const editionPaths = (() => {
return result
})()
console.log(JSON.stringify(editionPaths, null, 2))
// console.log(JSON.stringify(editionPaths, null, 2))
/** @type {import('next').NextConfig} */
const nextConfig = {

View File

@ -33,7 +33,11 @@
"@edition/*": [
"./app/edition/saas/*",
"./app/edition/community/*",
]
],
"~@edition/*": [
"./app/edition/saas/*",
"./app/edition/community/*",
],
}
},
"include": [