Skip to content

Instantly share code, notes, and snippets.

@treasonx
Created April 23, 2013 14:24
Show Gist options
  • Save treasonx/5443991 to your computer and use it in GitHub Desktop.
Save treasonx/5443991 to your computer and use it in GitHub Desktop.
Namespaced AMD
/*
This is the build config for my main JS file.
*/
({
baseUrl: "src/",
//wrap will wrap the entire script in an IIFE which will create private define/require functions
wrap: true,
out: 'dist/spxmain.js',
modules: [{
name: 'requireLib',
include: ['modules/analytics.spx',
'modules/storage.xdm',
'xmodules/easyxdm',
'slink',
'spxw/spxMain'],
exclude: ['jquery']
}],
//comment out for uglification
optimize: 'none',
paths : {
requireLib: 'libs/require'
}
})
/*
In my main.js file I expose define/require on my global namespace
which gives me isolation from anyother define/require that might already be on the page.
The creation of my global namespace is handled in the IIFE created by the build process.
*/
var NS = {
require: require,
define: define
};
window.NS = NS;
/*
This is the build config for other modules which will be dynamically loaded at runtime in production.
Again we want to wrap our module in an IIFE
*/
({
baseUrl: "src/",
//dir: "../out/",
wrap: true,
out: 'dist/modules/campaigns/AngularComponent.js',
modules: [{
name: 'requireLib',
include: ["modules/campaigns/AngularComponent"],
exclude: [
'utils/globalObject',
'spxw/SPX',
'spxw/Reporter',
'utils/BaseObject',
'utils/utils',
'text',
'jquery']
}],
optimize: 'none',
paths : {
//Notice here I am not using libs/require as my loader, I am using another script as my loader
requireLib: 'libs/spxamd'
}
})
/*
Here we want to expose define/require within the wrapped IIFE. This will allow the modules to register themselves properly
when loaded in production.
*/
var define = window.NS.define, require = window.NS.require;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment