File tree Expand file tree Collapse file tree 1 file changed +26
-16
lines changed Expand file tree Collapse file tree 1 file changed +26
-16
lines changed Original file line number Diff line number Diff line change @@ -35,25 +35,22 @@ export default defineConfig({
3535 {
3636 name : 'vue.worker' ,
3737 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-
38+ if ( id . includes ( 'vue.worker' ) ) {
5039 return {
51- code,
52- map : null
40+ code : patchVueWorker ( code ) ,
41+ map : null ,
5342 }
5443 }
55-
56- }
44+ } ,
45+ generateBundle ( _ , bundle ) {
46+ for ( const [ fileName , file ] of Object . entries ( bundle ) ) {
47+ if ( fileName . includes ( 'vue.worker' ) ) {
48+ // @ts -ignore
49+ file . source = patchVueWorker ( file . source . toString ( ) )
50+ break
51+ }
52+ }
53+ } ,
5754 } ,
5855 vue ( {
5956 script : {
@@ -84,3 +81,16 @@ export default defineConfig({
8481 exclude : [ '@vue/repl' ] ,
8582 } ,
8683} )
84+
85+ function patchVueWorker ( code : string ) {
86+ return `${ code }
87+ const pr = new URL(location.href).searchParams.get('pr')
88+ if(pr) {
89+ const _fetch = self.fetch
90+ 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\`) }
93+ return _fetch(...args)
94+ }
95+ }`
96+ }
You can’t perform that action at this time.
0 commit comments