Comments (11)
(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.
myModuleName
it not here beacuse UMD defines your module anonymously.
from umd.
@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.
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.
And every other script you wrote should be converted to an AMD module.
from umd.
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.
It is very easy put the content of ./lib/myModuleEntryPoint.js in place of require
.
Will your lib suffer from this?
from umd.
How does myModuleEntryPoint load other parts?
from umd.
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.
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.
awesome thanks!
from umd.
Related Issues (20)
- Readme.md headers are formatted incorrectly HOT 2
- AMD using require sugar syntax
- Start With CommonJS Instead of AMD? HOT 1
- Compatibility with webpack HOT 3
- UMD is not compatible with JavaScript modules HOT 12
- JavaScript Module shim for UMD bundles HOT 1
- Brace_umd project should be included in the README
- es6 module support? HOT 8
- UMD seems to be not quite clear for cases when you need multiple dependencies or none HOT 1
- jQuery compatible (but not required) + AMD + CommonJS? HOT 1
- xmsdk.js HOT 2
- Script Tag usage?
- Checks for CommonJS module environments are not fail-safe HOT 1
- Using UMD to create Singleton Instance across Micro Frontends HOT 1
- Include a history of UMD and when/why to use it
- Strict vs Returning variants with CommonJS support
- UMD should always immediately run factory HOT 1
- optional dependencies HOT 2
- Use UMD with JSDOM?
- templates/jqueryPlugin.js doesn't seem to conform to CommonJS spec HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from umd.