File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,7 @@ export const useStore = (initial: Initial) => {
8181 } )
8282 const hideFile = ! IS_DEV && ! userOptions . showHidden
8383
84+ if ( pr ) useWorker ( pr )
8485 const [ nightly , toggleNightly ] = useToggle ( false )
8586 const builtinImportMap = computed < ImportMap > ( ( ) => {
8687 let importMap = genImportMap ( versions , nightly . value )
@@ -290,4 +291,16 @@ export const useStore = (initial: Initial) => {
290291 return store as typeof store & typeof utils
291292}
292293
294+ function useWorker ( pr : string ) {
295+ const _worker = window . Worker ;
296+ window . Worker = class extends _worker {
297+ constructor ( url : URL | string , options ?: WorkerOptions ) {
298+ if ( typeof url === 'string' && url . includes ( 'vue.worker' ) ) {
299+ url = `${ url } ?pr=${ pr } `
300+ }
301+ super ( url , options ) ;
302+ }
303+ }
304+ }
305+
293306export type Store = ReturnType < typeof useStore >
Original file line number Diff line number Diff line change @@ -32,6 +32,29 @@ export default defineConfig({
3232 host : true ,
3333 } ,
3434 plugins : [
35+ {
36+ name : 'vue.worker' ,
37+ transform ( code , id ) {
38+ if ( id . includes ( 'vue.worker' ) ) {
39+ code = `${ code }
40+ const pr = new URL(location.href).searchParams.get('pr')
41+ if(pr) {
42+ const _fetch = self.fetch
43+ self.fetch = (...args) => {
44+ const shouldReplace = args[0].startsWith("https://cdn.jsdelivr.net/npm/element-plus/es/")
45+ if(shouldReplace) { args[0] = args[0].replace("https://cdn.jsdelivr.net/npm/element-plus", \`https://preview-\${pr}-element-plus.surge.sh/bundle\`) }
46+ return _fetch(...args)
47+ }
48+ }`
49+
50+ return {
51+ code,
52+ map : null
53+ }
54+ }
55+
56+ }
57+ } ,
3558 vue ( {
3659 script : {
3760 defineModel : true ,
You can’t perform that action at this time.
0 commit comments