File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 1313 "build:src" : " tsc" ,
1414 "build:electron" : " npm run server:setup && electron-builder build" ,
1515 "build:dir-only" : " npm run server:setup && electron-builder --dir" ,
16+ "postbuild" : " ts-node ./strip-preload-map.ts" ,
1617 "start" : " npm run server:setup && npm run start:app" ,
1718 "start:dev" : " ts-node ./skip-server.ts && cross-env HTK_DEV=true APP_URL='http://local.httptoolkit.tech:8080' npm run start:app" ,
1819 "start:app" : " tsc-watch --onSuccess \" electron .\" "
Original file line number Diff line number Diff line change 1+ import * as path from 'path' ;
2+ import { readFileSync , writeFileSync } from 'fs' ;
3+
4+ function removeSourceMapAnnotation ( filePath : string ) : void {
5+ const fileContent = readFileSync ( filePath , 'utf8' ) ;
6+ const lines = fileContent . split ( '\n' ) ;
7+
8+ if ( lines [ lines . length - 1 ] . startsWith ( '//# sourceMappingURL=' ) ) {
9+ lines . pop ( ) ; // Remove the last line
10+ } else {
11+ console . log ( `No sourcemap annotation found in ${ filePath } ` ) ;
12+ return ;
13+ }
14+
15+ const newContent = lines . join ( '\n' ) ;
16+ writeFileSync ( filePath , newContent , 'utf8' ) ;
17+ console . log ( `Sourcemap annotation removed from ${ filePath } ` ) ;
18+ }
19+
20+ // We have to strip the source map comment from here, otherwise when it loads
21+ // in Chrome, it tries to get preload.js.map from the real server, leaving
22+ // us with an annoying error because that's never going to work.
23+ const filePath = path . join ( __dirname , 'build' , 'preload.js' ) ;
24+ removeSourceMapAnnotation ( filePath ) ;
You can’t perform that action at this time.
0 commit comments