Skip to content

Commit

Permalink
Migrate to rollup. FIx sha256 browser dependency. Remove esbuild. Add…
Browse files Browse the repository at this point in the history
… esm browser build (#27)
  • Loading branch information
Kolezhniuk authored Oct 15, 2023
1 parent 89623bb commit 58b361d
Show file tree
Hide file tree
Showing 13 changed files with 2,582 additions and 1,278 deletions.
67 changes: 67 additions & 0 deletions config/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import commonJS from '@rollup/plugin-commonjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import tsConfig from '../tsconfig.json' assert { type: 'json' };
import packageJson from '../package.json' assert { type: 'json' };

const external = Object.keys(packageJson.peerDependencies || {});

const config = {
input: 'src/index.ts',
external,
output: [
{
format: 'es',
file: packageJson.exports['.'].browser,
sourcemap: true
}
],
treeshake: {
preset: 'smallest'
}
};

export default [
// esm browser
{
...config,
plugins: [
typescript({
compilerOptions: {
...tsConfig.compilerOptions
}
}),
commonJS(),
nodeResolve({
browser: true
}),
terser()
]
},
// umd browser
{
...config,
external: [],
plugins: [
typescript({
compilerOptions: {
...tsConfig.compilerOptions
}
}),
commonJS(),
nodeResolve({
browser: true
}),
terser()
],
output: [
{
format: 'iife',
file: packageJson.exports['.'].umd,
name: 'Iden3Core',
sourcemap: true
}
]
}
];
7 changes: 0 additions & 7 deletions config/tsconfig.esm.json

This file was deleted.

49 changes: 30 additions & 19 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible"
content="IE=edge">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<script src="./dist/umd/index.js"></script>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="./dist/browser/umd/index.js"></script>
<title>Test</title>
</head>
<script type="importmap">
{
"imports": {
"@iden3/js-crypto": "./node_modules/@iden3/js-crypto/dist/browser/esm/index.js"
}
}
</script>
</head>

<body>
Test UMD script work
</body>
<script>
const claim = Iden3Core.Claim.newClaim(new Iden3Core.SchemaHash(), Iden3Core.ClaimOptions.withFlagUpdatable(true));
const { index, value } = claim.rawSlots();
console.log(index, value, claim);
console.log(claim.hIndex());
console.assert(claim.value.length === 4);
</script>
<body>
Test UMD/ESM script work

<script type="module">
import * as esm from './dist/browser/esm/index.js';
function test(module) {
const { Claim, SchemaHash, ClaimOptions, BytesHelper } = module;
const claim = Claim.newClaim(new SchemaHash(), ClaimOptions.withFlagUpdatable(true));
const { index, value } = claim.rawSlots();
console.log(index, value, claim);
console.log(claim.hIndex());
console.assert(claim.value.length === 4);
console.log(BytesHelper.hashBytes('test'));
}
test(esm);
test(Iden3Core);
</script>
</body>
</html>
Loading

0 comments on commit 58b361d

Please sign in to comment.