-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Split NodeJS and browser setup #5
Conversation
Thank you for the PR. |
I'm sorry that I missed herumi/bls#65 . I'll check it again. |
@herumi This PR assumes that the wasm file is inlined in |
@herumi I've rebased this branch & PR on your dev branch after you've merged herumi/bls#65. Now you can run
and it should work fine |
I have one question. |
Yes, it is standard for |
Many thanks. I have a fews day off now. I'll check it later. |
I've pushed a commit to prevent breaking changes. If you prefer to have index.js as the entry point you can revert the last commit. Let me know if you have any more questions |
Your advice is very helpful. Many thanks. |
May I move setup for browser into bls.js? If it is not the standard way, then I'll revert it. |
Usually, web developers use bundling tools such as webpack which bundle all javascript code into a single file. In a similar fashion to emcc inlining the wasm file to bls_c.js. So usually the standard way is to not have code to inject global state the browser global window object. However, for the sake of simplicity in your .HTML example adding browser window injection code prevents having to add webpack to the project. I think is fine for now, I can do another PR afterwards showing you the webpack setup for a browser demo |
I'm now studying webpack and babel, etc. Please wait for a moment. |
If you need help in your study with a direct chat, please don't hesitate to say hi at our discord server https://discord.gg/QpMMT6Z3 |
@dapplion I'm sorry that your discord url is expored. I'm studying webpack and writing a sample code. In
in src/add_c.js, Could you give me some advice? |
@herumi The discord invite URL is public, don't worry. EMCC adds nodejs code which webpack fails to resolve because it's targeting the browser webpack-contrib/css-loader#447. To fix it set the target to node // webpack.config.js
module.exports = {
...
target: "node",
}; Note: If you name the config file |
That's very kind of you. |
You as developer of the library won't use webpack to distribute the library. Instead, consumers of the library will use webpack, mainly front-end developers. I would structure the repo as
So in case someone wants to use webpack for NodeJS they can use a different webpack configuration |
It sounds good. |
I have to say adding However, you can showcase your library on Github pages https://pages.github.com/ which would allow you greater flexibility. Such as splitting bls.js in more than one file, or writing it with Typescipt For the browser-demo, committing the package-lock.json is recommended. You can read more about it here https://docs.npmjs.com/cli/v6/configuring-npm/package-lock-json |
Thank you for all the advice.
You are right. But I'm not a frontend engineer and I have many tasks and I can't spend a lot of time to study it.
I see. |
I've removed |
While EXPORT_NAME is not mandatory it's use is recommended in the emcc docs. Since it's available in the global window object there can be naming collisions if someone uses more than one wasm factories within the same website |
Thanks for your advice. |
Should be merged with herumi/bls#65
Splits module initialization logic from BLS wrapper logic
bls.js
setup logic is reduced to 3 lines using thecreateBlsModule
function exported bybls_c.js
. If Inline wasm file for easier cross-platform setup bls#65 is mergedcreateBlsModule
returns an already initialized Module with the WASM source thanks to inlining.index.js
for NodeJS andbls-demo.js
. External library consumers can useindex.js
just as they did before withbls.js
. Thebls-demo.html
demo site works as before.