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

build(client): generate a UMD bundle #237

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lpinca
Copy link

@lpinca lpinca commented Jun 19, 2020

First commit

build(client): generate a UMD bundle
    
A UMD bundle can be used as a regular CommonJS module by bundlers and
included in other bundles.

Second commit

build(client): drop the .mjs extension
    
The .mjs extension is misleading as the generated bundle is not an
ECMAScript module and prevents bundlers from working properly.

lpinca added 2 commits June 19, 2020 21:26
A UMD bundle can be used as a regular CommonJS module by bundlers and
included in other bundles.
The .mjs extension is misleading as the generated bundle is not an
ECMAScript module and prevents bundlers from working properly.
@lpinca
Copy link
Author

lpinca commented Jun 19, 2020

Assume the following code is saved in an index.js file.

const { BrowserStorage, SocketProvider } = require('@webcrypto-local/client');

// Use `BrowserStorage` and `SocketProvider`.

Creating a bundle with index.js as entry point and running it in the browser should work as expected.

@rmhrisk
Copy link
Contributor

rmhrisk commented Jun 19, 2020

@lpinca I will have @microshine look at this but I am curious what app usage your working on? It is always neat to hear what people are doing with Fortify.

@rmhrisk rmhrisk requested a review from microshine June 19, 2020 20:31
@lpinca
Copy link
Author

lpinca commented Jun 19, 2020

@rmhrisk The plan is to use Fortify to create CAdES-BES signatures in the browser (I'm close to have a working demo) which will eventually be part of a much larger application.

@microshine
Copy link
Contributor

22.06.2020  19:35            63 109 index.es.js
22.06.2020  19:35            63 529 index.js
22.05.2020  14:02    <DIR>          types
22.06.2020  19:36           580 724 webcrypto-socket.js
22.06.2020  19:36           226 158 webcrypto-socket.min.js
22.06.2020  19:35           156 767 webcrypto-socket.min.mjs
22.06.2020  19:35           345 992 webcrypto-socket.mjs

Current version of client:
index.js - commonjs library in ES5. For NodeJS
index.es.js - library in ES2015
webcrypto-socket[.min].js - bundled file for browser in ES5. Uses global variable WebcryptoSocket for all exports
webcrypto-socket[.min].mjs - bundled file for browser in ES2015. Uses global variable WebcryptoSocket for all exports

@lpinca
Copy link
Author

lpinca commented Jun 22, 2020

You still get the global variable with this if you load the library in a <script> element. This allows the lib to be required and bundled with bundlers without forcing the user to use a <script> element and without exposing WebcryptoSocket in the global object.

The .mjs extension is used for ECMAScript modules and confuses webpack because webcrypto-socket{,min}.mjs are not ECMAScript modules.

@lpinca
Copy link
Author

lpinca commented Jun 22, 2020

There are still other dependencies that force the user to use a <script> element, like protobuf but that is a different issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants