requirejs

Access RequireJS path configuration

落爺英雄遲暮 提交于 2019-12-21 04:14:28
问题 I notice in the documentation there is a way to pass custom configuration into a module: requirejs.config({ baseUrl: './js', paths: { jquery: 'libs/jquery-1.9.1', jqueryui: 'libs/jquery-ui-1.9.2' }, config: { 'baz': { color: 'blue' } } }); Which you can then access from the module: define(['module'], function (module) { var color = module.config().color; // 'blue' }); But is there also a way to access the top-level paths configuration, something like this? define(['module', 'require'],

Loading jQuery with RequireJS - Which is better, a local version or a CDN one?

假装没事ソ 提交于 2019-12-21 04:09:11
问题 EDITED to clarify: In terms of performance (though that's still a wild term, I know), which is better - loading a local version, or a CDN version of jQuery, over RequireJS? For the record, RequireJS online doc contains some passage that seems to discourage CDN using, though I am not really sure 100% about what it means: Do not mix CDN loading with shim config in a build. Example scenario: you load jQuery from the CDN but use the shim config to load something like the stock version of Backbone

BlanketJS + Jasmine 2.0 not working

邮差的信 提交于 2019-12-21 04:06:35
问题 I have been testing with Jasmine 2.0.0 and it works without any problem. But there's a problem when I append BlanketJS to my code. I used a specRunner(https://github.com/alex-seville/blanket/blob/master/test/jasmine-requirejs/runner.html) that works with Jasmine 1.3.1. But It does not work when I replace Jasmine 1.3.1 with Jasmine 2.0.0, Here's original code from BlanketJS repo: <html> <head> <title>Jasmine Spec Runner</title> <link rel="stylesheet" type="text/css" href="../vendor/jasmine.css

Testing javascript with Chutzpah and requirejs

冷暖自知 提交于 2019-12-21 03:48:50
问题 I just wonder if there is a simple tutorial showing how to test javascript in visual studio with Chutzpah, require.js and jasmine. Basically, i want to run the tests without using an .html file so that i can see the results in the vs test explorer. 回答1: You can find some sample codes here: https://chutzpah.codeplex.com/SourceControl/latest#Samples/RequireJS/Jasmine/tests/base/base.jasmine.test.js Please note if you want to use requirejs with Chutzpah and Jasmine, you need to set

Can system.js replace require.js

做~自己de王妃 提交于 2019-12-21 03:42:55
问题 I'm using requirejs in a large project. This project will soon be upgraded to angular2. Angular2 uses system.js, so I'm thinking of switching to system.js too. Should I be able to remove the reference to the requirejs library and include system.js instead and expect it to work, or is there something I don't understand here? I tried by just removing the require.js file and adding the system.js file instead, but I get error messages saying define is not defined. Can you help? Will I need

Loading module once, requirejs with examples

感情迁移 提交于 2019-12-21 02:43:11
问题 I already ask similar question: Requirejs, what it means "Requirejs loads each module once" but in that topic no one answer the main question, because i asked in wrong way. So i will provide some easy examples to show on what i mean: Module counter.js 1: define([], function() { 2: console.log("Executing counter"); 3: var counter = 0; 4: 5: return { 6: increment: function() { counter++; }, 7: get: function() { return counter; } 8: }; 9: }); Module test1.js 1: define(['counter'], function

Alternatives to YepNope and LabJS

不羁岁月 提交于 2019-12-21 02:28:10
问题 I am wanting to load javascript and css files via a resource loader. I was originally using LabJs but I found YepNope more elegant and easier to work with in my scenario. However I am finding it devastatingly slow, which is odd as apparently it is comparable to LabJs in speed on most things. One thing I do have are Etags which I am sure will slow everything down as its still requesting from the server rather than just working off the client cache. Anyway there isnt much outside of the main

TypeScript compile AMD modules with required defines

廉价感情. 提交于 2019-12-21 01:57:37
问题 In AMD (as implemented in requirejs) one can defined modules to be included as dependencies, eg: define(['require','exports'], function(require, exports) { var externalDep = require('path/to/depModule'); // Use the module somewhere. }); I have tried the --module amd and it outputs correctly an AMD module usable by requirejs. Is it possible to define dependencies inside the source of TypeScript source file that translates to something like the example above? 回答1: You need to "export" your

requireJS with JQuery, Masonry, & ImagesLoaded: Object [object Object] has no method 'imagesLoaded'

情到浓时终转凉″ 提交于 2019-12-21 01:12:29
问题 RequireJS newbie here. Trying to convert some JQuery code I had working fine in the old way to work w/ RequireJS. Header of my page loads three JS files via script tags -- require.js itself, my require.cfg.js, and boot/main.js with the site-specific functionality. Relevant require.cfg.js excerpt: ,paths: { 'boot': 'src/boot' ,'jquery': 'lib/jquery.min' ,'jquery.masonry': 'lib/plugins/masonry.pkgd.min' ,'jquery.imagesloaded': 'lib/plugins/imagesloaded.pkgd.min' } ,shim: { 'jquery': { exports:

Can we export multiple non-AMD functions from a module in requirejs?

耗尽温柔 提交于 2019-12-20 20:41:03
问题 If I have a non-AMD module named old.js and inside this script I have two functions f1 and f2 defined. I need to use them, how do I export both? require.config({ paths: { "jquery": "https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min", }, shim: { "old": { deps: ["jquery"], exports: ["f1", "f2"] } }, urlArgs: "bust=" + (new Date()).getTime() }); This wouldn't work. I will get split error. The doc doesn't mention multiple (http://requirejs.org/docs/api.html#config-shim) I assume this