@@ -82,14 +82,16 @@ export default defineConfig(({ command, mode }) => {
8282 ] ,
8383 } ,
8484 } ) ,
85- {
86- name : 'replace-placeholder-baseurl' ,
87- closeBundle ( ) {
88- if ( command === 'build' && mode === 'proxy' ) {
89- setDynamicBaseUrl ( )
90- }
91- } ,
92- } ,
85+ // Deprecated: hacky proxy build
86+ // - - -
87+ // {
88+ // name: 'replace-placeholder-baseurl',
89+ // closeBundle() {
90+ // if (command === 'build' && mode === 'proxy') {
91+ // setDynamicBaseUrl()
92+ // }
93+ // },
94+ // },
9395 ] ,
9496 resolve : {
9597 alias : {
@@ -113,7 +115,7 @@ export default defineConfig(({ command, mode }) => {
113115 // Command: npm run build:proxy
114116 return {
115117 ...commonConfig ,
116- base : '/__PLACEHOLDER_BASEURL__ /' ,
118+ base : '/proxy/8024 /' ,
117119 build : {
118120 outDir : 'gui-build-proxy' ,
119121 rollupOptions : {
@@ -150,43 +152,45 @@ export default defineConfig(({ command, mode }) => {
150152 }
151153} )
152154
153- // To get the proxy build to work, we have to do some hacky post-processing
154- // by replacing our placeholder baseUrl with a dynamic one that includes
155- // whatever port is being used in our proxy url path.
156- function setDynamicBaseUrl ( ) {
157- // A. Update the index.html file:
158- const dir = resolve ( __dirname , 'gui-build-proxy' )
159- const indexPath = resolve ( dir , 'index.html' )
160- let indexHtml = readFileSync ( indexPath , 'utf-8' )
161-
162- // 1) Make the main JS and CSS file paths relative so they
163- // can be redirected using a dynamically generated base URL.
164- indexHtml = indexHtml . replace ( / \/ _ _ P L A C E H O L D E R _ B A S E U R L _ _ \/ / g, '' )
165-
166- // 2) Make the RDKit path relative.
167- indexHtml = indexHtml . replace ( / \/ r d k i t \/ R D K i t _ m i n i m a l \. j s / , 'rdkit/RDKit_minimal.js' )
168-
169- // 3) Activate the function that inserts the base URL tag
170- // and remove the js comments.
171- indexHtml = indexHtml . replace ( / < ! - - - - / , '' )
172- indexHtml = indexHtml . replace ( / \/ \/ .* / , '' )
173- indexHtml = indexHtml . replace ( / - - - - > / , '' )
174- writeFileSync ( indexPath , indexHtml )
175-
176- // B. Update the main JS file:
177- // 1) Find the name of the main JS file.
178- const jsFilename : string | null = indexHtml . match ( / < s c r i p t t y p e = " m o d u l e " c r o s s o r i g i n s r c = " a s s e t s \/ ( i n d e x - \w + .j s ) " > < \/ s c r i p t > / ) ?. [ 1 ] ?? null
179-
180- // 2) Run a find-and-replace inside the file.
181- if ( jsFilename ) {
182- const jsPath = resolve ( dir , `assets/${ jsFilename } ` )
183-
184- // Replace the placeholder baseUrl.
185- let jsFile = readFileSync ( jsPath , 'utf-8' )
186- jsFile = jsFile . replace (
187- / " \/ _ _ P L A C E H O L D E R _ B A S E U R L _ _ \/ " / g,
188- '`${window.location.pathname.match(/(.*)\\/proxy\\/\\d{4}/)?.[1] ?? ""}/proxy/${window.location.pathname.match(/\\/proxy\\/(\\d{4})/)?.[1] ?? 8024}/`' ,
189- )
190- writeFileSync ( jsPath , jsFile )
191- }
192- }
155+ // Deprecated: hacky proxy build
156+ // - - -
157+ // // To get the proxy build to work, we have to do some hacky post-processing
158+ // // by replacing our placeholder baseUrl with a dynamic one that includes
159+ // // whatever port is being used in our proxy url path.
160+ // function setDynamicBaseUrl() {
161+ // // A. Update the index.html file:
162+ // const dir = resolve(__dirname, 'gui-build-proxy')
163+ // const indexPath = resolve(dir, 'index.html')
164+ // let indexHtml = readFileSync(indexPath, 'utf-8')
165+
166+ // // 1) Make the main JS and CSS file paths relative so they
167+ // // can be redirected using a dynamically generated base URL.
168+ // indexHtml = indexHtml.replace(/\/__PLACEHOLDER_BASEURL__\//g, '')
169+
170+ // // 2) Make the RDKit path relative.
171+ // indexHtml = indexHtml.replace(/\/rdkit\/RDKit_minimal\.js/, 'rdkit/RDKit_minimal.js')
172+
173+ // // 3) Activate the function that inserts the base URL tag
174+ // // and remove the js comments.
175+ // indexHtml = indexHtml.replace(/<!----/, '')
176+ // indexHtml = indexHtml.replace(/\/\/ .*/, '')
177+ // indexHtml = indexHtml.replace(/---->/, '')
178+ // writeFileSync(indexPath, indexHtml)
179+
180+ // // B. Update the main JS file:
181+ // // 1) Find the name of the main JS file.
182+ // const jsFilename: string | null = indexHtml.match(/<script type="module" crossorigin src="assets\/(index-\w+.js)"><\/script>/)?.[1] ?? null
183+
184+ // // 2) Run a find-and-replace inside the file.
185+ // if (jsFilename) {
186+ // const jsPath = resolve(dir, `assets/${jsFilename}`)
187+
188+ // // Replace the placeholder baseUrl.
189+ // let jsFile = readFileSync(jsPath, 'utf-8')
190+ // jsFile = jsFile.replace(
191+ // /"\/__PLACEHOLDER_BASEURL__\/"/g,
192+ // '`${window.location.pathname.match(/(.*)\\/proxy\\/\\d{4}/)?.[1] ?? ""}/proxy/${window.location.pathname.match(/\\/proxy\\/(\\d{4})/)?.[1] ?? 8024 }/`',
193+ // )
194+ // writeFileSync(jsPath, jsFile)
195+ // }
196+ // }
0 commit comments