-
-
Notifications
You must be signed in to change notification settings - Fork 784
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
ES6 Modules #262
Comments
This would be much appreciated!
mocha unit tests
index.html
|
I would love to see this happen, in the mean time, load it from |
Does 31fc5b7 help or make it easy to add by adding an es6 target? |
btw if you have a script tag in your head section loading fuse.js you all the classes and functions are available under the |
It is for more control, sometimes you don't need to put it on global, or don't need to load |
That sounds like you're looking for something like dynamic imports, which as far as I know ought to work with the webpack generated UMD (fuse*.js that are in dist/). If it doesn't work can you show a minimal test case along with any error messages? |
We don't use webpack anymore so it would be great to have the module option for pure JavaScript. It doesn't have to be a dynamic import, static is fine. I just don't need it as a global in every file, but prefer to have it statically imported in just the files that need it. |
@KonradHoeffner Your project doesn't need to use webpack to consume a library that does. You ought to be able to just import fuse.js as things are today. Or is the objection that the library is built with webpack? If so, why (honest question, if there is a good reason to object to webpack I'd like to know for my own projects and things I depend on)? I presume you're not building from fuse.js' source since if you were you could use your own build tooling and this would be a non-issue. Trying to understand exactly what is being asked for. My understanding is that webpack umd is an ES2015 module in environments that support them, so I think the title and premise of this bug might be outdated, so am trying to clarify. |
Sorry for the confusion. I have absolutely no problem with using a library that uses Webpack, I just meant that our project doesn't use it and that as far as I know, UMD and ES6 modules are different systems that are not compatible, so I understood your post as though Webpack somehow makes the two compatible by rewriting ES6 code to UMD code, so if I don't use Webpack, my ES6 import code would not be rewritten to UMD. I will create a minimal working example. |
With ES6 module support, I'll be able to run Fuse directly in the browser: <script type="module">
import Fuse from '/path/to/fuse.esm.js';
const fuse = new Fuse(options);
</script> As an example, presently I've to import Fuse as a global at https://respec.org/xref/ (using the UMD bundle). That means, I can't use <script src="fuse.js"></script> <!-- can't defer this, otherwise script.js will face race conditions -->
<script src="script.js" type="module"></script> A ESM build would also allow running fuse in Deno and Node v13+ with ESM support. |
@cshoredaniel: I just tested it with version 3.6.1 and it does not work as a module right now, as the following code fails:
I also tried it locally with the npm module via So it seems like Webpack does actually not create an ES6 module automatically. |
Thanks. I'll look into this more deeply. The docs I read claimed to ES2015. Since that's clearly not the case, I apologize for the confusion (and will see if I can find a solution). |
Probably need to use rollup instead: webpack/webpack#2933 |
@sidvishnoi thanks. I don't remember where I saw the es2015 thing -- probably misread something. Anyway it does looks like rollup is the best option for getting the umd modules we have now plus an es6 module (or es6 min and unmin). Time to read docs and learn something new... |
I'd welcome testing and comments of #365 (Switch bundler to Rollup) |
@cshoredaniel: Thanks, that works perfectly!
Opening the HTML file below in the browser results in the following output, so I assume it works:
|
- Added ES6 modules for bundlers and browsers (fixed #262) - Added CommonJS - Added UMD - Name change so that .min actually reflects the minified version
- Changed bundler to Rollup - Added ES6 modules for bundlers and browsers (fixed #262) - Added CommonJS builds - Added UMD builds - Name change so that .min actually reflects the minified version
Is there a real reason, why we don't ship ES6 modules?
I would like to see an additional export at this point, I would also do a PR, if wished and needed.
Regards,
Johann
The text was updated successfully, but these errors were encountered: