requirejs

Require.js lazy loading remote url

余生长醉 提交于 2019-12-22 05:01:30
问题 I have a file called moment.js on my local file system and loading it as follows with require.js works: initialize: function() { require(['moment'], function(data) { console.log(data); }); } However, if I do: initialize: function() { require(['http://momentjs.com/downloads/moment.min.js'], function(data) { console.log(data); }); } data comes back undefined. Why is this? and how do I dynamically include remote modules at runtime? 回答1: I noticed that the code you are trying to load hardcodes

Using Angular Dragula without RequireJS

非 Y 不嫁゛ 提交于 2019-12-22 02:02:51
问题 I would love to implement Drag and Drop in my Angular project using the angular-dragula module (https://github.com/bevacqua/angular-dragula). However, it seems to be heavily dependent on RequireJS. I've not used Require for a while and only then for an example app or two. Is there an easy way to untangle Require from this module? The author seems to think it is simple (https://github.com/bevacqua/angular-dragula/issues/23) and has shut down similar questions as well without a real explanation

Require.js module not seeing Backbone Router.js

梦想与她 提交于 2019-12-22 01:32:57
问题 In this simple Require/Backbone app https://github.com/thisishardcoded/require-prob Why does app.js see Router but TestView.js not? Here is the first line of app.js define(['router'],function (Router) { and here is the first line of TestView.js define(['backbone','router'],function(Backbone,Router){ Check out the repo for full details, download, run and check console log if you feel so inclined Thanks! Jim More: Ok, the answer is - because of the order in which it is loaded and even if that

Pattern for Backbone app using requirejs

北城余情 提交于 2019-12-22 00:23:20
问题 I came across this article about about backbone apps with requirejs. There is one thing that seems really odd. Whenever they need a reference of Backbone, Underscore or jquery in my module I have to require them: define([ 'jQuery', 'Underscore', 'Backbone', 'collections/projects', ], function($, _, Backbone, ProjectsCollection, projectsListTemplate){ var projectListView = Backbone.View.extend({ el: $("#container"), ... So is there really a need to go that way? Isn't a bit over engineered?

RequireJS paths config saying “all modules are in this file”

白昼怎懂夜的黑 提交于 2019-12-21 22:47:05
问题 In RequireJS, it's possible to configure paths explicitly for given modules. For example, you can specify that for module foo the module bar should be loaded instead (file bar.js should be loaded): require.config({ paths: { "foo": "bar" } }); How can I do the same, but for all modules? I tried using an asterisk, but it will only create a mapping for module * literally: require.config({ paths: { "*": "bar" } }); 回答1: According to your question and comment The TypeScript compiler is able to

How to solve a conflict between browserify (Backbone based app) and require.js on the same page?

半城伤御伤魂 提交于 2019-12-21 19:38:09
问题 I have a backbone app up and running correctly. It's meant to be used as a widget in 3rd pages. Unfortunately, I just realised that one of these pages has already Backbone / underscore loaded. I get errors such as this: Uncaught TypeError: Cannot read property 'extend' of undefined Which usually appear when underscore has not been previously loaded. My typical view is like this: (normal Backbone view) ./view1.js var Backbone = require('backbone') var _ = require('underscore') var $ = require(

Create a MVC route ending “.js” and returning JavaScript?

对着背影说爱祢 提交于 2019-12-21 12:32:54
问题 I'd like to auto-generate some JavaScript files, with proper .js extensions in their URLs, using ASP.NET MVC 5. Here's my problem; I'm using require.js throughout my site and it's working pretty well. However, not all of my JavaScript files are real files on disk. Some of them must be generated at runtime. So I've written a controller which generates the dynamic JavaScript files, and serves them when using the default routing; // ~/Resource/CommonRes -- from ResourceController.CommonRes()

backbone.js + require.js + user authentication

若如初见. 提交于 2019-12-21 11:22:24
问题 Started learning backbone.js and require.js. Not sure how to structure files for web app with user authentication. Seems it should flow like this: On app init, query server to check auth session state; Q#1: where should I be writing this 'after init' session code - in /js/app.js? Q#2: should I be using jQuery ajax for this, or is there better backbone.js methods (I've seen references to get(), fetch(), toJSON() in examples)? If success, store auth data in a model (user_id, username, auth

require.js + backbone.js: How to structure modules that have an initialize function?

坚强是说给别人听的谎言 提交于 2019-12-21 05:32:05
问题 I have an application with three pages (which are single-page interfaces). The pages have similar but not identical functionality. So I want to have javascript-modules that provide the common functionality. Then each page may customize/overwrite parts of the common functionality. I'm using backbone.js, so what I do is: load the files containing the common Models, Views, Collections etc. load app-specific files that customize/overwrite parts of step 1 call an init() function that instanciates

Backbone.js how to i18n value before passing to template

你离开我真会死。 提交于 2019-12-21 05:17:15
问题 Using Backbone.js, Handlebars and Require.js with i18n. I have my en_us.js file with all the string translations, but how do I deal with the case of dynamic values being sent to the template? I know all these strings ahead of time, but hard coding them into the template seems messy, can I pass in a pre-translated string some how? I am using the hbs module for the i18n and templates with require.js. 回答1: I see this problem not related to i18n but to any case where you need render data that