Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(browser-support): add target to esbuild options #19

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe, 1.2.0 at least?

"author": "hCaptcha team and contributors",
"license": "MIT",
"keywords": [
Expand Down