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

Support browser ES6 imports #110

Open
mdaffin opened this issue Sep 3, 2019 · 1 comment
Open

Support browser ES6 imports #110

mdaffin opened this issue Sep 3, 2019 · 1 comment

Comments

@mdaffin
Copy link

mdaffin commented Sep 3, 2019

It would be nice to be able to use elasticlunr as an ES6 import which are now supported by most major browsers. This allows better code organisation and keeps the global name space cleaner. A minimal example that almost works:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <script defer async type="module">
      import * as elasticlunr from "http://elasticlunr.com/elasticlunr.js";
    </script>
  </head>
  <body></body>
</html>

But results in the error:

eferenceError: assignment to undeclared variable lunrelasticlunr.js:90:1
    <anonymous> http://elasticlunr.com/elasticlunr.js:90
    <anonymous> http://elasticlunr.com/elasticlunr.js:2507
    InnerModuleEvaluation self-hosted:4147
    InnerModuleEvaluation self-hosted:4136
    evaluation self-hosted:4101

And fails to actually work and adding a var to line 90 then results in this error:

TypeError: root is undefinedelasticlunr.js:2497:26
    <anonymous> http://127.0.0.1:1111/elasticlunr.js:2497
    <anonymous> http://127.0.0.1:1111/elasticlunr.js:2499
    <anonymous> http://127.0.0.1:1111/elasticlunr.js:2507
    InnerModuleEvaluation self-hosted:4147
    InnerModuleEvaluation self-hosted:4136
    evaluation self-hosted:4101
@airhorns
Copy link

I feel like it might be best to wrap the code that adds the global alias in a function so that users can invoke it if they need it, and otherwise not try to muck around with the global?

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

No branches or pull requests

2 participants