Skip to content

Commit

Permalink
fix(browser-support): add target to esbuild options (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
faris-imi authored Jan 24, 2024
1 parent 2c1e320 commit 537bc1d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
70 changes: 38 additions & 32 deletions lib/esbuild.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path, { resolve } from 'path';
import { fileURLToPath } from 'url';

import { build, context, analyzeMetafile } from 'esbuild';
import * as dotenv from 'dotenv'
import * as dotenv from 'dotenv';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Expand All @@ -13,7 +13,7 @@ const SRC = resolve(__dirname, 'src');

dotenv.config({
path: `${ROOT}/.env`
})
});

const BUILD = process.env.BUILD || 'production';
const DEBUG = process.env.DEBUG === 'true';
Expand All @@ -27,7 +27,7 @@ const config = {
external: ['@hcaptcha/types'],
tsconfig: 'tsconfig.json',
define: {
'process.env.SENTRY_DSN_TOKEN': JSON.stringify(SENTRY),
'process.env.SENTRY_DSN_TOKEN': JSON.stringify(SENTRY),

},

Expand All @@ -46,36 +46,42 @@ const config = {


if (WATCH) {
const ctx = await context({
...config,
format: 'esm',
outfile: resolve(DIST, 'index.mjs'),
treeShaking: true
});
await ctx.watch();
const ctx = await context({
...config,
format: 'esm',
outfile: resolve(DIST, 'index.mjs'),
treeShaking: true,
target: [
'es6'
]
});
await ctx.watch();
} else {
const resultESM = await build({
...config,
format: 'esm',
outfile: resolve(DIST, 'index.mjs'),
treeShaking: true
});
const resultESM = await build({
...config,
format: 'esm',
outfile: resolve(DIST, 'index.mjs'),
treeShaking: true,
target: [
'es6'
]
});

const resultCJS = await build({
...config,
format: 'cjs',
outfile: resolve(DIST, 'index.cjs'),
treeShaking: true
});
const resultCJS = await build({
...config,
format: 'cjs',
outfile: resolve(DIST, 'index.cjs'),
treeShaking: true
});

if (DEBUG) {
const analyzeESM = await analyzeMetafile(resultESM.metafile, {
verbose: false
});
const analyzeCJS = await analyzeMetafile(resultCJS.metafile, {
verbose: false
});
console.log(analyzeESM);
console.log(analyzeCJS);
}
if (DEBUG) {
const analyzeESM = await analyzeMetafile(resultESM.metafile, {
verbose: false
});
const analyzeCJS = await analyzeMetafile(resultCJS.metafile, {
verbose: false
});
console.log(analyzeESM);
console.log(analyzeCJS);
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hcaptcha/loader",
"description": "This is a JavaScript library to easily configure the loading of the hCaptcha JS client SDK with built-in error handling.",
"version": "1.1.2",
"version": "1.1.3",
"author": "hCaptcha team and contributors",
"license": "MIT",
"keywords": [
Expand Down

0 comments on commit 537bc1d

Please sign in to comment.