@@ -2,7 +2,7 @@ import path, { resolve } from 'path';
22import { fileURLToPath } from 'url' ;
33
44import { build , context , analyzeMetafile } from 'esbuild' ;
5- import * as dotenv from 'dotenv'
5+ import * as dotenv from 'dotenv' ;
66
77const __filename = fileURLToPath ( import . meta. url ) ;
88const __dirname = path . dirname ( __filename ) ;
@@ -13,7 +13,7 @@ const SRC = resolve(__dirname, 'src');
1313
1414dotenv . config ( {
1515 path : `${ ROOT } /.env`
16- } )
16+ } ) ;
1717
1818const BUILD = process . env . BUILD || 'production' ;
1919const DEBUG = process . env . DEBUG === 'true' ;
@@ -27,7 +27,7 @@ const config = {
2727 external : [ '@hcaptcha/types' ] ,
2828 tsconfig : 'tsconfig.json' ,
2929 define : {
30- 'process.env.SENTRY_DSN_TOKEN' : JSON . stringify ( SENTRY ) ,
30+ 'process.env.SENTRY_DSN_TOKEN' : JSON . stringify ( SENTRY ) ,
3131
3232 } ,
3333
@@ -46,36 +46,42 @@ const config = {
4646
4747
4848if ( WATCH ) {
49- const ctx = await context ( {
50- ...config ,
51- format : 'esm' ,
52- outfile : resolve ( DIST , 'index.mjs' ) ,
53- treeShaking : true
54- } ) ;
55- await ctx . watch ( ) ;
49+ const ctx = await context ( {
50+ ...config ,
51+ format : 'esm' ,
52+ outfile : resolve ( DIST , 'index.mjs' ) ,
53+ treeShaking : true ,
54+ target : [
55+ 'es6'
56+ ]
57+ } ) ;
58+ await ctx . watch ( ) ;
5659} else {
57- const resultESM = await build ( {
58- ...config ,
59- format : 'esm' ,
60- outfile : resolve ( DIST , 'index.mjs' ) ,
61- treeShaking : true
62- } ) ;
60+ const resultESM = await build ( {
61+ ...config ,
62+ format : 'esm' ,
63+ outfile : resolve ( DIST , 'index.mjs' ) ,
64+ treeShaking : true ,
65+ target : [
66+ 'es6'
67+ ]
68+ } ) ;
6369
64- const resultCJS = await build ( {
65- ...config ,
66- format : 'cjs' ,
67- outfile : resolve ( DIST , 'index.cjs' ) ,
68- treeShaking : true
69- } ) ;
70+ const resultCJS = await build ( {
71+ ...config ,
72+ format : 'cjs' ,
73+ outfile : resolve ( DIST , 'index.cjs' ) ,
74+ treeShaking : true
75+ } ) ;
7076
71- if ( DEBUG ) {
72- const analyzeESM = await analyzeMetafile ( resultESM . metafile , {
73- verbose : false
74- } ) ;
75- const analyzeCJS = await analyzeMetafile ( resultCJS . metafile , {
76- verbose : false
77- } ) ;
78- console . log ( analyzeESM ) ;
79- console . log ( analyzeCJS ) ;
80- }
77+ if ( DEBUG ) {
78+ const analyzeESM = await analyzeMetafile ( resultESM . metafile , {
79+ verbose : false
80+ } ) ;
81+ const analyzeCJS = await analyzeMetafile ( resultCJS . metafile , {
82+ verbose : false
83+ } ) ;
84+ console . log ( analyzeESM ) ;
85+ console . log ( analyzeCJS ) ;
86+ }
8187}
0 commit comments