Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #699 from SuperViz/fix/kick-participant-interval
Browse files Browse the repository at this point in the history
feat: improve esm build
  • Loading branch information
carlossantos74 authored Jun 27, 2024
2 parents c479264 + 10ad452 commit 696136e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
12 changes: 4 additions & 8 deletions .esbuild/build.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
const config = require('./config');
const { cjsConfig, esmConfig } = require('./config');
const esbuild = require('esbuild');

(async () => {
try {
await Promise.all([
esbuild.build({
...config,
format: 'cjs',
outdir: 'lib',
outExtension: { '.js': '.cjs' },
...cjsConfig,
outfile: 'lib/index.cjs.js',
}),

esbuild.build({
...config,
format: 'esm',
...esmConfig,
outdir: 'lib',
splitting: true,
}),
]);
} catch (error) {
Expand Down
34 changes: 32 additions & 2 deletions .esbuild/config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
require('dotenv').config();
const { style } = require('./plugins/style-loader');
const glob = require('glob');

const entryPoints = glob
.sync('./src/**/*.ts')
.filter((file) => !file.endsWith('.d.ts') && !file.endsWith('.test.ts'));

const entries = Object.entries(process.env).filter((key) => key[0].startsWith('SDK_'));
const env = Object.fromEntries(entries);

const config = {
entryPoints: ['./src/index.ts'],
loader: {
'.png': 'file',
'.svg': 'file',
Expand All @@ -26,4 +30,30 @@ const config = {
},
};

module.exports = config;
const esmConfig = {
...config,
entryPoints,
bundle: true,
sourcemap: true,
minify: true,
splitting: true,
format: 'esm',
define: { global: 'window' },
target: ['esnext'],
chunkNames: 'chunks/[name]-[hash]',
};

const cjsConfig = {
...config,
entryPoints: ['src/index.ts'],
bundle: true,
sourcemap: true,
minify: true,
platform: 'node',
target: ['node16'],
};

module.exports = {
esmConfig,
cjsConfig,
};
12 changes: 4 additions & 8 deletions .esbuild/watch.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
const config = require('./config');
const { cjsConfig, esmConfig } = require('./config');
const esbuild = require('esbuild');

(async () => {
try {
const [cjsContext, esmContext] = await Promise.all([
esbuild.context({
...config,
format: 'cjs',
outdir: 'dist',
outExtension: { '.js': '.cjs' },
...cjsConfig,
outfile: 'dist/index.cjs.js',
}),

esbuild.context({
...config,
format: 'esm',
...esmConfig,
outdir: 'dist',
splitting: true,
}),
]);

Expand Down

0 comments on commit 696136e

Please sign in to comment.