requirejs

How to access node.js module in RequireJS (AMD) environment?

柔情痞子 提交于 2019-12-19 02:57:16
问题 I have a front-end SPA using RequireJS (2.1.14) as module system. It basically bootstrap and load Backbone.Marionette app. In main.js : require.config ({ baseUrl: '/js', waitSeconds: 200, nodeRequire: require, paths: { jquery: '//cdn/jquery.min', underscore:'//cdn/underscore-min', // more plugins }, shim: { // shimming stuff } }); require(['marionette', 'vent', 'config/template', 'app', 'routers/main' ], function (Marionette, vent, Template, nrtApp ) { 'use strict'; nrtApp.module ('Public

Load Nodejs Module into A Web Worker

荒凉一梦 提交于 2019-12-19 02:54:14
问题 I'm intending to use web worker inside my Node.js application for some concurrent tasks. However since the 'webworker-threads' module follows the implementation of HTML5 web worker, requiring Nodejs modules like require("fs") inside web worker does not work. importScripts() can load js files but I would like a functionality inside the web worker so that I can require npm-installed modules. Is there a workaround for that? 回答1: author of webworker-threads here. Thank you for using the module!

Circular Dependencies in modules using requireJs

你说的曾经没有我的故事 提交于 2019-12-19 01:14:53
问题 Reading the requireJs documentation, in order to fix the Circular Dependencies, is suggested to use exports to create an empty object for the module that is available immediately for reference by other modules. I try this code but it seems to do not work. What is wrong? P.S.: read the comments for seeing the output, especially the B module inside setTimeout call. // A module define([ 'b' ], function (b) { console.log('B:', b); // B, Object var A = { boo: 1 }; return A; }); // B module define(

Circular Dependencies in modules using requireJs

帅比萌擦擦* 提交于 2019-12-19 01:12:47
问题 Reading the requireJs documentation, in order to fix the Circular Dependencies, is suggested to use exports to create an empty object for the module that is available immediately for reference by other modules. I try this code but it seems to do not work. What is wrong? P.S.: read the comments for seeing the output, especially the B module inside setTimeout call. // A module define([ 'b' ], function (b) { console.log('B:', b); // B, Object var A = { boo: 1 }; return A; }); // B module define(

requirejs load script progress

天涯浪子 提交于 2019-12-18 14:53:29
问题 Risking of asking a stupid question I will give it a try though. Is it possible to display a progress indicator while RequireJs is loading dependencies? For example: require(['jquery'], function($) { // Well, jQuery loaded in quite some time due to a low-speed connection // // Or maybe I wanted to show an overlay to prevent user of clicking on UI widgets until the load is complete }); I don't want to start modifying the RequireJS source if there's some plugin out there which didn't show up in

How to load ckeditor via requirejs

守給你的承諾、 提交于 2019-12-18 13:01:33
问题 I'm having issues trying to load ckeditor via requirejs (I've tried converting the main ckeditor js file into individual modules but that has just caused all hell to break loose) and so I'm now checking to see if there is a very simple way to do this that I've missed. I know requirejs allows you to load normal js scripts so maybe just loading the ckeditor.js file (un-edited, so it's still an IIFE/self-executing function) - would that work with requirejs or if you're using requirejs for

TypeScript: compiling removes unreferenced imports

狂风中的少年 提交于 2019-12-18 11:41:19
问题 In our project we're using RequireJS as our module loader. Some of our modules will influence global libraries, and hence won't be directly used within the module they are referenced in. Example: define(['definitely/goingto/usethis/','just/referencingthis/forpackaging'], function(useThis) { useThis.likeIPromised(); // the following call can only be made when the second required file is available someGlobalAvailableVariable.someMethod(); }); This works as expected when writing my modules in

Why doesn't chrome.tabs.query() return the tab's URL when called using RequireJS in a Chrome extension?

眉间皱痕 提交于 2019-12-18 11:09:29
问题 I have a simple Chrome extension that adds a browser action. When the extension's popup is opened, it needs to access the current tab's URL. Since it doesn't need access to all the tabs, I just have the activeTab permission specified in the manifest: { "manifest_version": 2, "name": "RequireJS Test", "version": "0.0.1", "description": "Test RequireJS and the activeTab permission.", "permissions": [ "activeTab" ], "browser_action": { "default_popup": "popup.html" }, "web_accessible_resources":

Module pattern- How to split the code for one module into different js files?

我的未来我决定 提交于 2019-12-18 10:17:08
问题 For the module pattern, I'm doing something like: (function(namespace) { // tons of code // blabla })(window.myGlobalNamespace); How do I split the code? I can think of a few ways, like use a hierachy of namespaces, or expand the object outside by window.myGlobalNamespace.additionalFunc = function () {//blabla} . What are the other ways? What are the pros and cons? Which one is considered better practice? Both of the two answers suggest RequireJS. Can you please explain how RequireJS can

Sourcing jQuery from a CDN?

对着背影说爱祢 提交于 2019-12-18 10:11:42
问题 I am using require JS and want to know the best method to use a CDN version of jQuery. I hear the 1.7 version is "AMD" which is supposed to help but can't find a straight example. Hope some RequireJS gurus can help me out. 回答1: jQuery 1.7 registers itself as an AMD module by the name of 'jquery', so you need to create a mapping for 'jquery' using the paths config: requirejs.config({ paths: { 'jquery' : 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min' } }); require(['jquery'],