requirejs

RequireJS text plugin: cannot load HTML from other domain

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-02 15:02:49
问题 I'd like to fetch some html from another domain with require.js. I know that CORS policies doesn't allow this easily. Note: I have configured the web server (with Access-Control-Allow-Origin "*" and other directives) and require.js so far that all JS and CSS files (css with require-css plugin) gets loaded from the other domain as expected - just fetching html makes problems. But in the browser network protocol I can see that the html content even gets loaded. However, this content does not

Write Requirejs modules that work without requirejs

大兔子大兔子 提交于 2020-01-02 13:32:28
问题 I would like to create my modules in a way, that they can be used with and without requirejs (without require js they should just work normally, so I have to make sure they load correctly, like putting script tags in the right order). So jQuery does it kindof like this: // export module if ( typeof define === "function" && define.amd ) { define(["dep"], function(dep){ dep.fn.test = test; return dep; }); } else{ dep.fn.test = test; } The actual module is defined as like so var dep = function(.

Use require.js to run common code before module is required

左心房为你撑大大i 提交于 2020-01-02 06:58:29
问题 I'm using Moment.js on a few different pages in an international site. Each page uses require.js to require in Moment. Moment allows you to set the locale to display dates in that locales format. However, this code has to be run on every page Moment is loaded (since I'm never sure which page the user loads first). var Moment = require('moment'); // configure locale What I want to do is move the code to configure the locale to something like a pre-require step so that I don't have to remember

what does var io = require('../..')(server) do?

流过昼夜 提交于 2020-01-02 06:32:10
问题 I've build the project https://github.com/Automattic/socket.io/tree/master/examples/chat locally and it is working great. However, it would be nice to understand a little more about how a socket application works. In the main startup script one of the modules that is pulled in with require is var io = require('../..')(server) what does require('../..') do? thanks! 回答1: When a path to a directory is given to require , it will implicitly look for an index.js in that directory. In this case, it

Context and nested modules in requireJS

旧时模样 提交于 2020-01-02 05:29:07
问题 I'm having a bit of trouble with contexts in requireJS. What I'd like to is create a context, "mycontext", at the config stage (before I load any modules), and then have that context kept throughout. This is complicated because I am unfortunately required (<- ha!) to use the CommonJS syntax for my modules. So, if this is my base file looks like this: base.js contextReq = require.config({ context: 'mycontext', baseUrl: 'http://www.example.com/src/', paths:{ jquery: 'http://ajax.cdnjs.com/ajax

Requirejs can't compile my dojo-dependent module

梦想的初衷 提交于 2020-01-02 05:01:16
问题 UPDATE: I tried Jeff Barczewski's answer below, and though I no longer get the error below for plugins, I am now getting a different error: Error: TypeError: Cannot read property 'normalize' of undefined In module tree: mymodule/core at Object.<anonymous> (/usr/local/lib/node_modules/requirejs/bin/r.js:1193:35) UPDATE 2: Since Jeff is correct that Dojo's plugins are not compatible with RequireJS, I decided to switch to using grunt-dojo instead for building dojo. I still use RequireJS for my

Way to bundle require.js source with main.js

浪子不回头ぞ 提交于 2020-01-01 19:29:13
问题 I have a unique situation where I need to have both the source and main.js in one file and for everything to initialize within that file, so no require calls on the page. Is this possible? 回答1: If you want to include require.js with the main.js source, you can use this kind of command: node ../../r.js -o baseUrl=. paths.requireLib=../../require name=main include=requireLib out=main-built.js Since "require" is a reserved dependency name, you create a " requireLib " dependency and map it to the

BreezeJs with dedicated web worker

半世苍凉 提交于 2020-01-01 17:43:10
问题 I am trying to initialize a Breeze manager inside a 'Web Worker'. RequireJs, knockout, q, breeze are being imported inside the worker. After a call to: EntityQuery.from('name').using(manager).execute() , the following error appears: Uncaught Error: Q is undefined. Are you missing Q.js? See https://github.com/kriskowal/q . A live preview is uploaded here http://plnkr.co/edit/meXjKa?p=preview (plunk supports downloading for easier debug). EDIT -- relevant code Worker.js importScripts('knockout

BreezeJs with dedicated web worker

ⅰ亾dé卋堺 提交于 2020-01-01 17:43:06
问题 I am trying to initialize a Breeze manager inside a 'Web Worker'. RequireJs, knockout, q, breeze are being imported inside the worker. After a call to: EntityQuery.from('name').using(manager).execute() , the following error appears: Uncaught Error: Q is undefined. Are you missing Q.js? See https://github.com/kriskowal/q . A live preview is uploaded here http://plnkr.co/edit/meXjKa?p=preview (plunk supports downloading for easier debug). EDIT -- relevant code Worker.js importScripts('knockout

AngularJS RequireJS Browserify and the Javascript module/global scope nightmare [closed]

我的未来我决定 提交于 2020-01-01 09:47:10
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I have been digging a bit lately in all this CommonJS vs AMD battle and this is my findings... ( BTW I am not preaching here I am sharing my thoughts to get some constructive insights... ) The RequireJS brings to much complexity to my Angular modules, it feel wrong to me as