Open alex-w0 opened 6 years ago
Hello @DevelGitH,
I know how module.exports
work. But as Lazy is a client-side script, what should I export? Could you give me an example what you want to be exported and how you use it? I'm open for any improvement!
Hi @eisbehr- , thank´s for your answear. Yeah thats true, that you cannot export your library, when you have a client-side script. A solution would be to put your code into a object class or function and afterwards you can export the function with module.exports.
The problem is when i`m trying to import your lazy-load script, it throws an error at the line 43 of the file jquery.lazy.js ($.fn is not defined), because the variable window.$ from the main script couldn´t be passed to your script.
My Code is the following:
//Import jQuery Library
import $ from 'jquery';
window.$ = window.jQuery = $;
import './lib/jquery.lazy';
$("img.lazy").Lazy();
I will keep this open as an enhancement. But I need to think about the implementation.
Hi, I'm using Zurb Foundation CLI, installed it via npm and tried:
import 'jquery-lazy';
copied file to lib folder and tried:
import import './lib/jquery.lazy';
these solutions doesn't work for me, I get this error:
Uncaught TypeError: Cannot read property 'fn' of undefined
How can I import library to my project?
The error sounds like you didn't added jQuery
to your project, because fn
is only used register the plugin within jQuery.
I've used the same import approach as if the first comment:
import $ from 'jquery';
window.$ = window.jQuery = $;
Do you know that this is an issue and it is still open? Why do you think it will work for you, if it would not work for others?!
The only solution that I found was pasting import statements on top of the jquery.lazy.js file:
import $ from 'jquery';
window.$ = window.jQuery = $;
/*!
* jQuery & Zepto Lazy - v1.7.9
* http://jquery.eisbehr.de/lazy/
*
* Copyright 2012 - 2018, Daniel 'Eisbehr' Kern
*
* Dual licensed under the MIT and GPL-2.0 licenses:
* http://www.opensource.org/licenses/mit-license.php
Now it works for me and hope will work for others.
Yeah but that solution wouldn't be nice. The jquery library will now be imported twice, when the developer is using the library in his project. Have a look at other libraries, they aren't importing the required libs in their project.
Yes, I know that problem. In the new version of Lazy the import problem is solved and there is no dependency on jQuery anymore. But I can't actually tell when the release will be ready. I think I will publish the first draft within the next time.
Unfortunately this is still an issue. Any news on the new version?
Please use in your library the function module.exports to allow requiring the module with the es6 command "import"
http://stackabuse.com/how-to-use-module-exports-in-node-js/