forked from opentiny/tiny-vue
fix(sites): fix error relative path in playground (#959)
* fix(sites): fix error relative path in playground * fix(sites): fix error relative path in playground * fix(sites): fix error relative path in playground
This commit is contained in:
parent
4247eab395
commit
b8810cc059
|
@ -28,7 +28,7 @@
|
|||
import { ref } from 'vue'
|
||||
import Svgs from '@opentiny/vue-icon'
|
||||
import { Modal, Input as TinyInput } from '@opentiny/vue'
|
||||
import { iconGroups } from './iconGroups'
|
||||
import { iconGroups } from './iconGroups.js'
|
||||
|
||||
const all = Object.values(iconGroups).flat()
|
||||
iconGroups.Others = Object.keys(Svgs).filter((name) => !all.includes(name) && name[0] === 'I')
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<script>
|
||||
import Svgs from '@opentiny/vue-icon'
|
||||
import { Modal, Input } from '@opentiny/vue'
|
||||
import { iconGroups } from './iconGroups'
|
||||
import { iconGroups } from './iconGroups.js'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
|
|
|
@ -37,7 +37,8 @@ const $pub = (url) => {
|
|||
* @returns
|
||||
*/
|
||||
const fetchDemosFile = (path) => {
|
||||
return fetch(baseUrl + path, {
|
||||
const filePath = baseUrl + path
|
||||
return fetch(filePath, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'text/plain;charset=UTF-8'
|
||||
|
@ -45,13 +46,33 @@ const fetchDemosFile = (path) => {
|
|||
}).then((res) => {
|
||||
if (res.ok) {
|
||||
return res.text().then((text) => {
|
||||
return text.replace(/(\$\{)?import\.meta\.env\.VITE_APP_BUILD_BASE_URL(\})?/g, (str) => {
|
||||
// 处理相对路径引入
|
||||
text = text.replace(/import.+('|")((\.\/|\.\.\/).+)('|")/g, (...args) => {
|
||||
const [matchStr, , relativePath, type] = args
|
||||
const pathArr = filePath.split('/')
|
||||
if (type === './') {
|
||||
const relativeFilename = relativePath.replace('./', '')
|
||||
pathArr.splice(-1, 1, relativeFilename)
|
||||
return matchStr.replace(relativePath, pathArr.join('/'))
|
||||
} else if (type === '../') {
|
||||
const relativePathArr = relativePath.split('../')
|
||||
const len = relativePathArr.length
|
||||
pathArr.splice(-len)
|
||||
pathArr.push(relativePathArr[len - 1])
|
||||
return matchStr.replace(relativePath, pathArr.join('/'))
|
||||
} else {
|
||||
return matchStr
|
||||
}
|
||||
})
|
||||
// 处理静态资源路径
|
||||
text = text.replace(/(\$\{)?import\.meta\.env\.VITE_APP_BUILD_BASE_URL(\})?/g, (str) => {
|
||||
if (str.startsWith('$')) {
|
||||
return import.meta.env.VITE_APP_BUILD_BASE_URL
|
||||
} else {
|
||||
return `'${import.meta.env.VITE_APP_BUILD_BASE_URL}'`
|
||||
}
|
||||
})
|
||||
return text
|
||||
})
|
||||
} else {
|
||||
throw new Error(res.statusText)
|
||||
|
|
Loading…
Reference in New Issue