Code Monkey home page Code Monkey logo

Comments (11)

szepeviktor avatar szepeviktor commented on June 10, 2024
(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        // AMD. Register as an anonymous module.
        define(['b'], factory);
    } else {
        // Browser globals
        root.amdWeb = factory(root.b);
    }
}(this, function (b) {
    This is the place(for your script);
    Another script called(b, "is required to run your script");
    b's return can be accessed as "b" here;
    At the end return something. Take a look at ("other AMD-friendly scripts", "what they return");
    E.g. you could put everything in an object and return(that);
    return Something;
}));

from umd.

szepeviktor avatar szepeviktor commented on June 10, 2024

myModuleName it not here beacuse UMD defines your module anonymously.

from umd.

kumavis avatar kumavis commented on June 10, 2024

@szepeviktor thanks for the clarification 😸
I think my confusion is mostly coming from a lack of understanding of AMD

I mostly work with browserify, and I'm looking for a wrapper to put on the top that would expose my module globally, via browserify, or to AMD. When my work is distributed as a universal module, it would be a browserify bundle, that would not have any dependencies ( they would all be included ).

I'm guessing this would look like:

(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        // AMD. Register as an anonymous module.
        define([], factory);
    } else if ( typeof module === 'object' ) {
        // Browser globals
        module.exports = factory();
    } else {
        self.MyModule = factory();
    }
}(this, function () {
    return require('./lib/myModuleEntryPoint.js');
}));

does that look correct? I don't know what the implications of defining my module anonymously are, but it seems like something I might not want?

from umd.

szepeviktor avatar szepeviktor commented on June 10, 2024

Once you go AMD, you need to use an AMD loader: curl.js or require.js
If you concatenate all your modules into one js file use almond.js
So this block

return require('./lib/myModuleEntryPoint.js');

should contain your modules's code.

from umd.

szepeviktor avatar szepeviktor commented on June 10, 2024

And every other script you wrote should be converted to an AMD module.

from umd.

kumavis avatar kumavis commented on June 10, 2024

I'm not interested in converting to AMD, just making my module consumable by someone using an AMD system. When bundling, Browserify will provide my module at the require line.

}(this, function () {
    return require('./lib/myModuleEntryPoint.js');
}));

So it sounds like this should work.

This is the kind of template I would expect to be on this repo. "Browserify Developer? wrap your code in this. AMD Developer? wrap your code in this." That seems close to what you're doing, but it was not clear what I needed to do. Or am I misunderstanding the goal of the repo?

from umd.

szepeviktor avatar szepeviktor commented on June 10, 2024

It is very easy put the content of ./lib/myModuleEntryPoint.js in place of require.
Will your lib suffer from this?

from umd.

szepeviktor avatar szepeviktor commented on June 10, 2024

How does myModuleEntryPoint load other parts?

from umd.

kumavis avatar kumavis commented on June 10, 2024

browserify handles that. The result will be a single file with all contents, the object I'm trying to export is returned from the require statement

from umd.

szepeviktor avatar szepeviktor commented on June 10, 2024

If it is one file it can be wrapped in UMD. It will run in a browser and can be loaded as an AMD module.

from umd.

kumavis avatar kumavis commented on June 10, 2024

awesome thanks!

from umd.

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.