Skip to content

Commit

Permalink
fix(esbuild): different builds cjs/ems/iife
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanGerbeth committed Dec 20, 2021
1 parent 28f9189 commit a7554a8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
43 changes: 39 additions & 4 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,46 @@
import { build } from 'esbuild';
import browserslistToEsbuild from 'browserslist-to-esbuild';

build({
entryPoints: ['./src/index.js'],
const inputs = [
{ src: './src/index.js', name: 'basics.vector', target: '' },
{ src: './src/operator.js', name: 'basics.vector.operator' },
{ src: './src/adapter/playcanvas.js', name: 'basics.vector.adapter.playcanvas'}
];

const defaultOptions = {
bundle: true,
minify: true,
sourcemap: true,
treeShaking: true,
target: browserslistToEsbuild(),
outfile: './build/out.js',
}).catch(() => global.process.exit(1));
mainFields: ['module', 'main'],
outbase: 'src'
};

inputs.forEach((item) => {
build({
...defaultOptions,
entryPoints: [item.src],
format: 'iife',
globalName: item.name,
outdir: './build/iife',
}).catch(() => global.process.exit(1));

build({
...defaultOptions,
entryPoints: [item.src],
format: 'esm',
splitting: true,
outdir: './build/esm/',
outExtension: { '.js': '.mjs' }
}).catch(() => global.process.exit(1));

build({
...defaultOptions,
entryPoints: [item.src],
format: 'cjs',
outdir: './build/cjs/',
outExtension: { '.js': '.cjs' }
}).catch(() => global.process.exit(1));
});

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"version": "2.0.0-beta.1",
"description": "A 3D Vector lib including arithmetic operator overloading (+ - * / % **).",
"type": "module",
"module": "build/esm/index.mjs",
"main": "build/cjs/index.cjs",
"directories": {
"build": "build"
},
Expand Down

0 comments on commit a7554a8

Please sign in to comment.