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

Declare a "main file" or index.js in the generated module #94

Closed
mstange opened this issue Apr 19, 2018 · 7 comments · Fixed by #95
Closed

Declare a "main file" or index.js in the generated module #94

mstange opened this issue Apr 19, 2018 · 7 comments · Fixed by #95
Labels
enhancement New feature or request PR attached there's a PR open for this issue to-do stuff that needs to happen, so plz do it k thx
Milestone

Comments

@mstange
Copy link
Contributor

mstange commented Apr 19, 2018

In the wasm-add example, the main JS file in the generated module is wasm-add/wasm_add.js. This means that you have to specify the JS filename when importing that module e.g. through webpack.

If the generated JS file were called index.js instead, or if its name was declared as the main file using the main property in the module's package.json, one would be able to use just import("wasm-add") to import the module, which would be a bit nicer.

This would also allow the "test in your browser" button on the npm package site to work more smoothly. For example, if you click that button on https://www.npmjs.com/package/@mgattozzi/wasm-add, you get to https://npm.runkit.com/@mgattozzi/wasm-add, which says:

@mgattozzi/wasm-add lists no main file and has no index.js, so it can't be directly required. If this is a mistake, please let us know. It may however contain internal files that you can require manually

@ashleygwilliams
Copy link
Member

hey! so it would be pretty trivial to declare the file as main in the package.json and/or rename it. which do you prefer, i don't have a strong opinion. index.js is idiomatic. i'm tempted to do both! let me know what you think @mstange and we can get that done!

@ashleygwilliams ashleygwilliams added question Further information is requested to-do stuff that needs to happen, so plz do it k thx enhancement New feature or request labels Apr 19, 2018
@ashleygwilliams ashleygwilliams added this to the 0.2.0 milestone Apr 19, 2018
@ashleygwilliams ashleygwilliams added the PR attached there's a PR open for this issue label Apr 19, 2018
@mstange
Copy link
Contributor Author

mstange commented Apr 19, 2018

Sounds good!

My intuition would be to use index.js unless there's a good reason not to. And if you have an index.js I don't think you need a main in the package.json.

@mstange
Copy link
Contributor Author

mstange commented Apr 19, 2018

But I don't know enough about npm packages to say whether not using index.js has any disadvantages, so I think either is fine.

@ashleygwilliams
Copy link
Member

yeah if we call it index.js we don't have to throw it in main, but i might do it anyways :)

@ashleygwilliams ashleygwilliams removed the question Further information is requested label Apr 19, 2018
@ashleygwilliams
Copy link
Member

this should land shortly and ideally 0.2.0 can be released very soon! thanks for bringing this up!

@mstange
Copy link
Contributor Author

mstange commented Apr 19, 2018

Thanks for fixing it so quickly! Also, wasm-pack is an awesome tool!

@mgattozzi
Copy link
Contributor

Ohhh so that's why the es6 module require wasn't working. Thanks! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PR attached there's a PR open for this issue to-do stuff that needs to happen, so plz do it k thx
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants