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

npm module without the universal module definition boilerplate #10

Closed
dashed opened this issue Sep 8, 2016 · 3 comments
Closed

npm module without the universal module definition boilerplate #10

dashed opened this issue Sep 8, 2016 · 3 comments

Comments

@dashed
Copy link

dashed commented Sep 8, 2016

Kudos for this library!

I'm wondering if there is a possibility for an npm module without the universal module definition (umd) boilerplate:

!function (root, factory) {
if (typeof module === 'object' && module.exports)
module.exports = factory(root);
else
root.timeago = factory(root);
}(typeof window !== 'undefined' ? window : this, function () {

@hustcc
Copy link
Owner

hustcc commented Sep 9, 2016

you mean like this:

(function (root, factory) {
    if (typeof exports === 'object') {
        module.exports = factory();

    } else if (typeof define === 'function' && define.amd) {
        define(factory);

    } else {
        root.eventUtil = factory();
    }
})(this, function() {
    // your module
});

or what ?

@dashed
Copy link
Author

dashed commented Sep 9, 2016

To clarify, I'm asking if there may be an npm module without the universal module definition wrapping code, so as to keep the library light when used with module bundlers like webpack or browserify.

Example:

var timeago = function(nowDate, defaultLocale) {
    // ...

};

module.exports = timeago;

This might require a change in how timeago.js is packaged for npm, browser, etc.

Feel free to close this issue if this is a wontfix.

@hustcc
Copy link
Owner

hustcc commented Sep 9, 2016

If just module.exports = timeago;, it will more tiny, but the library will can not be used with scirpt tag:

<script src="dist/timeago.min.js"></script>

so many user just use it with script to import it.

@hustcc hustcc closed this as completed Sep 10, 2016
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