requirejs

Backbone + RequireJS: Making Collection Persisting?

 ̄綄美尐妖づ 提交于 2019-12-24 01:50:25
问题 I'm using Backbone with RequireJS, and my View needs to switch between like, say, 20 collections corresponding to respective RESTful APIs. The "normal" way handles things fine, except that for each API a new Collection needs to be defined, resulting in a hugely bloated codebase: Collection (x 20 times) define(function(require) { var Backbone = require('backbone'); var c = Backbone.Collection.extend({ url: '/path/to/api-1' }); return new c(); }); View define(function(require) { var Backbone =

Callback before RequireJS “define” function is called?

社会主义新天地 提交于 2019-12-24 00:38:31
问题 I'm new to Backbone, and i'm helping to maintain an app that has lots of Backbone and RequireJS code that does something like so: define( ['backbone', 'underscore'], function(Backbone, _) { // some code here } ); I'd like to configure Underscore in each of these pages... In the most simple sense, I could just do something like so: define( ['backbone', 'underscore'], function(Backbone, _) { // do some stuff to configure underscore configureUnderscore(_); } ); but I'd like to leave each page's

Backbone not defined with require js

≯℡__Kan透↙ 提交于 2019-12-24 00:19:51
问题 I'm getting Model not defined error with below code. I've added underscore, jquery, backbone etc but I can only get object returned with console.log function for jquery only $ Is there a reason why other objects are not returning inside define function? Below is my code from main.js: require.config({ paths: { jquery: '//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min', underscore: '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min', backbone: '//cdnjs.cloudflare.com

Using require.js with 3rd party javascript libraries

感情迁移 提交于 2019-12-23 22:24:17
问题 I'm just starting to use require.js and think it's great. However, I would like to use it as much as possible instead of dealing with <script> tags in my HTML files. To that end, is it possible to work with a 3rd party library that doesn't have any define modules in it? This may be asking much I realize but is there a way to call... require(["3rd_party"], function(3rd) { }); ...where 3rd_party.js is a script located in a js folder that require knows to look in? I know require has mapping

Using Vue JS with Require JS?

喜欢而已 提交于 2019-12-23 13:32:51
问题 I installed the following via Bower: jQuery 3.1.0 Vue 1.0.26 Require.js 2.2.0 But when I load my site, "Vue" is undefined. I tried var vue = require('Vue') and stuff, but it doesn't seem to work. Vue says it is a AMD module and so is Require.js... What am I missing? 回答1: var vue = require('Vue') won't work by itself. Either you: Change it to the form of require that takes a callback: require(['Vue'], function (vue) { // code that uses Vue }); Or put your require call in a define call: define

RequireJS calling callbacks before dependencies loaded/resolved

我的未来我决定 提交于 2019-12-23 13:09:00
问题 I'm having an issue with RequireJS where my main.js script has a reference to a dependency, which is loaded but not resolved when the callback in main.js requesting this dependency is run. My directory structure is: index.htm scripts/ require.js main.js feeds/ feed.js index.htm: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Blah</title> <script data-main="scripts/main" src="scripts/require.js"></script> </head> <body> <h1>Hello, World!</h1> </body> </html> main.js: require([

RequireJs optimizer ignore plugin

对着背影说爱祢 提交于 2019-12-23 13:01:10
问题 I would like to ignore the use of a require js plugin when I use the optimizer define(["css!styles.css"]) This always gives me this error Cannot read property 'normalize' of undefined . I've set this options to the require optimizer { paths : { 'css' : 'empty:' } } But it keeps giving me the error. 回答1: I don't know if that is what you want, but you could stub out the css plugin. //Specify modules to stub out in the optimized file. The optimizer will //use the source version of these modules

require js jquery plugins

早过忘川 提交于 2019-12-23 11:24:46
问题 Do I have to write wrappers for each jQuery plugin I am trying to use in require.js? I can't user the order plugin they still give me the error that they depend on jQuery. Thanks 回答1: RequireJS 2.0 has a shim option that allows you to use older non-AMD scripts as modules - http://requirejs.org/docs/api.html#config-shim 回答2: Have you read How to use require js with jquery? It explains that you can use require js to load jquery and jquery plugins by using a combined jquery/requirejs file. You

RequireJS not working in IE9

梦想的初衷 提交于 2019-12-23 09:34:33
问题 I'm experiencing a fairly peculiar behavior - my RequireJS modules seem to be not initializing and running at all under IE9: <head> ... <script data-main="/static/js/main" src="/static/js/libs/require.js"></script> // Seems to be not running at all. </head> However, whenever I fire up IE9's developer tool, and reload the page , the modules will be running fine just as they should in Firefox/Chrome/Safari/etc. Cleaning browser cache and closing the developer tool in IE9 will render the

How do I make Require.js fetch a script that does not end in `.js`? [duplicate]

时光总嘲笑我的痴心妄想 提交于 2019-12-23 09:32:19
问题 This question already has answers here : Is it possible to stop requireJS from adding the .js file extension automatically? (3 answers) Closed 6 years ago . I'm developing an app that uses a certain site to make payments easier, and the way it handles payments requires to import some javascript from this url https://bridge.paymill.com/ that contains the script. The fact is, I'm using require js to load all the scripts, in my main.js configuration, I'm trying to make it this way: requirejs