Skip to content

Commit b0c52da

Browse files
DsaquelDsaquel
andauthored
fix: use esm.sh for PR preview instead of surge.sh (#342)
Co-authored-by: Dsaquel <onoblet@nukk.ai>
1 parent c49342a commit b0c52da

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/composables/store.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ export const useStore = (initial: Initial) => {
5151
: undefined
5252
const pr =
5353
new URLSearchParams(location.search).get('pr') ||
54-
saved?._o?.styleSource?.split('-', 2)[1]
55-
const prUrl = `https://preview-${pr}-element-plus.surge.sh/bundle/dist`
54+
saved?._o?.styleSource?.match(/element-plus@([^/]+)/)?.[1]
55+
const prUrl = `https://raw.esm.sh/pr/element-plus@${pr}/dist`
5656
const vuePr =
5757
new URLSearchParams(location.search).get('vue') || saved?._o?.vuePr
5858
const vuePrUrl = `https://esm.sh/pr`
@@ -89,7 +89,7 @@ export const useStore = (initial: Initial) => {
8989
importMap = mergeImportMap(importMap, {
9090
imports: {
9191
'element-plus': `${prUrl}/index.full.min.mjs`,
92-
'element-plus/': 'unsupported',
92+
'element-plus/': `https://raw.esm.sh/pr/element-plus@${pr}/`,
9393
},
9494
})
9595

vite.config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ export default defineConfig({
8585
function patchVueWorker(code: string) {
8686
return `${code}
8787
const pr = new URL(location.href).searchParams.get('pr')
88-
if(pr) {
88+
if (pr) {
8989
const _fetch = self.fetch
9090
self.fetch = (...args) => {
91-
const shouldReplace = args[0].startsWith("https://cdn.jsdelivr.net/npm/element-plus/es/")
92-
if(shouldReplace) { args[0] = args[0].replace("https://cdn.jsdelivr.net/npm/element-plus", \`https://preview-\${pr}-element-plus.surge.sh/bundle\`) }
91+
if (typeof args[0] === 'string' && /https:\\/\\/cdn\\.jsdelivr\\.net\\/npm\\/element-plus(@[^/]+)?\\//.test(args[0])) {
92+
args[0] = args[0].replace(/https:\\/\\/cdn\\.jsdelivr\\.net\\/npm\\/element-plus(@[^/]+)?/, \`https://raw.esm.sh/pr/element-plus@\${pr}\`)
93+
}
9394
return _fetch(...args)
9495
}
9596
}`

0 commit comments

Comments
 (0)