GithubHelp home page GithubHelp logo

Comments (7)

pwoolcoc avatar pwoolcoc commented on July 25, 2024

I tried something right after I posted this. If I set 'localforage' as an alias to localforage.min in my requirejs config, it works fine:

requirejs.config({
    "baseUrl": "js/lib",
    "paths": {
        "app": "../app",
        "localforage": "localforage.min"
    }
});

requirejs(["app/main"]);

app/main.js

define(["localforage"], function(lf) {
    console.log(lf); // => Object { INDEXEDDB="asyncStorage", LOCALSTORAGE="localStorageWrapper", WEBSQL="webSQLStorage", more...} main.js (line 3)
});

from localforage.

magalhas avatar magalhas commented on July 25, 2024

Not sure, but since you're specifying .min requirejs may assume that .min is the file extension. Try require(['localforage.min.js'], though the config approach is a better one imo.

from localforage.

magalhas avatar magalhas commented on July 25, 2024

Oh sorry, didn't notice that your console.log was being executed. But this appears to be a requirejs bug and not a problem with localforage.

from localforage.

tofumatt avatar tofumatt commented on July 25, 2024

@jrburke Any chance you could fill me in on if this is a require bug/quirk or something I've done wrong? Does requiring localForage as "localforage.min" cause errors? Keep in mind if define is available localForage does:

define('localforage', function() {
    return localForage;
});

as seen here.

from localforage.

jrburke avatar jrburke commented on July 25, 2024

@tofumatt it is best if the define calls are anonymous in source form, so just define(function(){.... That will allow 'localforage.min' references to work.

In the larger picture, I also suggest for consumers of this lib that are using modules to use 'localforage' as the ID as that plays well with any other library that might want the same (they will just ask for 'localforage' anyway, will not know about if minified), and if a minified version is wanted, use a paths config, as the second comment does, to point to that minified version.

And going a step further, I would not use the minified version in source form in a project: I suggest using the non-minified forms in source, then rely on an r.js build step to do any minifications. This allows better debugging if you need to step into the source of a dependency, and the whole project minification will lead to better results over just specific files being minified.

But back to the more immediate question, an anonymous define() call is best practice. More details here.

from localforage.

magalhas avatar magalhas commented on July 25, 2024

As said above, an anonimous define will fix the issue. I'll make a PR when I have some time if no one dibbs on that.

from localforage.

tofumatt avatar tofumatt commented on July 25, 2024

Works for me.

from localforage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.