How to use requirejs - 10 common examples

To help you get started, we’ve selected a few requirejs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zhoukekestar / modules / optimizer.js View on Github external
var optimizeModules = function(index, callback) {

  if (index >= currentModules.length) {
    return callback(null, results);
  }
  config.name = currentModules[index];
  // console.log(config.name + ' is optimizing...');
  requirejs.optimize(config, function (buildResponse) {
    results += currentContent;
    return optimizeModules(index + 1, callback);
  }, function(err) {
    callback(err)
  });
}
github alberto-acevedo / cesium-navigation / Examples / build.js View on Github external
// This only builds the sources for the example amd.html
// all other examples do not need to be built.

var requirejs = require('requirejs');

var config = {
    baseUrl: '.',
    optimize: 'uglify2',
    mainConfigFile: 'Source/mainConfig.js',
    name: "Source/amd/main",
    out: "Build/amd.min.js",
    logLevel: 0
};

requirejs.optimize(config);
github lazojs / lazo / lib / server / app.js View on Github external
serverConf.paths.bundler = serverConf.paths.lazoBundle;
                    }
                    if (fs.existsSync(customAssetPath)) {
                        serverConf.paths.assets = path.resolve(path.normalize(LAZO.FILE_REPO_DIR + '/app/assets'));
                    }
                    if (fs.existsSync(customServerSetup)) {
                        serverConf.paths.appServerSetup = path.resolve(path.normalize(LAZO.FILE_REPO_DIR + '/app/server/server'));
                    }
                    if (fs.existsSync(customPageTemplate)) {
                        serverConf.paths.pageTemplate = path.resolve(path.normalize(LAZO.FILE_REPO_DIR + '/app/views/page.hbs'));
                    }

                    return serverConf;
                }

                LAZO.require = requirejs.config(addPaths(serverConf));
                LAZO.contexts = {
                    request: JSON.parse(JSON.stringify(clientConf)), // request combo handling
                    lib: JSON.parse(JSON.stringify(clientConf)), // lib combo handling
                    server: JSON.parse(JSON.stringify(serverConf)), // paths are used for generating combo handled file
                    app: {
                        shim: conf.shim,
                        paths: conf.paths
                    }
                };

                // these are needed by dependencies of lazoApp
                LAZO.isServer = true;
                LAZO.isClient = false;
                // these cannot be loaded until the requirejs app config has been set
                LAZO.require(['config'], function (config) {
                    LAZO.config = config;
github fwextensions / QuicKey / build / scripts / build-popup.js View on Github external
// switch some of the libraries to mocked versions so that we can require
	// the App component outside of a browser
config.paths = _.assign(config.paths, {
	cp: "../../build/mock/cp",
		// the mock tracker needs to create a window global and then require
		// the original tracker module
	"original-tracker": "background/tracker",
	"background/tracker": "../../build/mock/tracker"
});

	// we're running in the top level directory, so add src to get to the
	// normal baseUrl that the app uses
config.baseUrl = "src" + config.baseUrl;

requirejs.config(config);

	// requirejs seems to run asynchronously and the paths get all weird running
	// this from grunt, so we have to run it as a plain node script and do the
	// writing of the rendered HTML inside the required module
requirejs([
	"jsx!popup/app"
], function(
	App
) {
	const newReactMarkup = ReactDOMServer.renderToString(React.createElement(App, {
		initialQuery: "",
		initialShortcuts: [],
		platform: "win",
		tracker: {
			set: function() {}
		},
github ibm-js / grunt-amd-build / tasks / lib / requirejs.js View on Github external
// Add requirejs build settings.
	config.inlineText = config.inlineText || true;
	config.isBuild = true;
	config.nodeRequire = require;

	config.config = config.config || {};
	config.config["requirejs-dplugins/has"] = config.config["requirejs-dplugins/has"] || {};
	config.config["requirejs-dplugins/has"].builder = true;

	// Set up global config
	requirejs.config(config);

	// Set up context config
	config.context = context;
	var req = requirejs.config(config);

	// Take a path relative to the Gruntfile and return the node equivalent.
	req.getNodePath = requirejs.getNodePath;

	return req;
};
github gruntjs / grunt-contrib-requirejs / tasks / requirejs.js View on Github external
} catch (e) {
        grunt.fail.warn('There was an error while processing your done function: "' + e + '"');
      }
    };

    // The following catches errors in the user-defined `error` function and passes them.
    // if the error function options is not set, this value should be undefined
    var tryCatchError = function(fn, done, err) {
      try {
        fn(done, err);
      } catch (e) {
        grunt.fail.fatal('There was an error while processing your error function: "' + e + '"');
      }
    };

    requirejs.optimize(
            options,
            tryCatchDone.bind(null, options.done, done),
            options.error ? tryCatchError.bind(null, options.error, done):undefined
    );

  });
};
github ringcentral / ringcentral-js / lib / index.js View on Github external
(function() {

    'use strict';

    // Exports

    module.exports = require('requirejs').config({baseUrl: __dirname, nodeRequire: require})('./RCSDK')({
        CryptoJS: require('crypto-js'),
        localStorage: require('dom-storage'),
        Promise: require('es6-promise').Promise,
        PUBNUB: require('pubnub'),
        XHR: require('xhr2')
    });

})();
github AnalyticalGraphicsInc / cesium / gulpfile.js View on Github external
gulp.task('requirejs', function(done) {
    var config = JSON.parse(Buffer.from(process.argv[3].substring(2), 'base64').toString('utf8'));

    // Disable module load timeout
    config.waitSeconds = 0;

    requirejs.optimize(config, function() {
        done();
    }, done);
});
github erkobridee / lab-nodejs / js_until_es5.1 / bundlers / requirejs_build / node.js / 01 / build / lib / builder.js View on Github external
function builder( config ) {

  // config.out = outputConsole;
  requirejs.optimize(config, buildResponse, buildError);

}
github BorderTech / wcomponents / wcomponents-theme / build-js.js View on Github external
return new Promise(function(win, lose) {
		requirejs.optimize(conf, function (buildResponse) {
			noisyLog(buildResponse);
			console.timeEnd("buildJS");
			win();
		}, function(err) {
			console.error(err);
			lose(err);
		});
	});
}

requirejs

Node adapter for RequireJS, for loading AMD modules. Includes RequireJS optimizer

MIT
Latest version published 4 months ago

Package Health Score

83 / 100
Full package analysis

Popular requirejs functions