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

Migrate to rollup. FIx sha256 browser dependency. Remove esbuild. Add esm browser build #27

Merged
merged 1 commit into from
Oct 15, 2023
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
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
Loading