1
1
import * as process from "process" ;
2
2
import * as esbuild from "esbuild" ;
3
+ import { readFileSync } from "fs" ;
3
4
import { umdWrapper } from "esbuild-plugin-umd-wrapper" ;
4
5
import yargs from "yargs" ;
5
6
import { hideBin } from "yargs/helpers" ;
@@ -25,11 +26,29 @@ myYargs
25
26
;
26
27
const argv = await myYargs . argv ;
27
28
29
+ const excludeSourceMapPlugin = ( { filter } ) => ( {
30
+ name : 'excludeSourceMapPlugin' ,
31
+ setup ( build ) {
32
+ build . onLoad ( { filter } , ( args ) => {
33
+ return {
34
+ contents :
35
+ readFileSync ( args . path , 'utf8' ) +
36
+ '\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==' ,
37
+ loader : 'default' ,
38
+ } ;
39
+ } ) ;
40
+ } ,
41
+ } ) ;
42
+
28
43
function build ( config ) {
29
44
argv . debug && console . log ( "Start: " , config . entryPoints [ 0 ] , config . outfile ) ;
30
45
return esbuild . build ( {
31
46
...config ,
32
- sourcemap : true
47
+ sourcemap : "linked" ,
48
+ plugins : [
49
+ ...config . plugins ?? [ ] ,
50
+ excludeSourceMapPlugin ( { filter : / n o d e _ m o d u l e s / } ) ,
51
+ ]
33
52
} ) . then ( ( ) => {
34
53
argv . debug && console . log ( "Stop: " , config . entryPoints [ 0 ] , config . outfile ) ;
35
54
} ) ;
@@ -38,15 +57,19 @@ function build(config) {
38
57
function watch ( config ) {
39
58
return esbuild . context ( {
40
59
...config ,
41
- sourcemap : "external" ,
42
- plugins : [ ...config . plugins ?? [ ] , {
43
- name : "rebuild-notify" ,
44
- setup ( build ) {
45
- build . onEnd ( result => {
46
- console . log ( `Built ${ config . outfile } ` ) ;
47
- } ) ;
48
- } ,
49
- } ]
60
+ sourcemap : "linked" ,
61
+ plugins : [
62
+ ...config . plugins ?? [ ] ,
63
+ excludeSourceMapPlugin ( { filter : / n o d e _ m o d u l e s / } ) ,
64
+ {
65
+ name : "rebuild-notify" ,
66
+ setup ( build ) {
67
+ build . onEnd ( result => {
68
+ console . log ( `Built ${ config . outfile } ` ) ;
69
+ } ) ;
70
+ } ,
71
+ }
72
+ ]
50
73
} ) . then ( ctx => {
51
74
return ctx . watch ( ) ;
52
75
} ) ;
0 commit comments