requirejs

Using almond with grunt-contrib-requirejs

邮差的信 提交于 2019-12-07 02:34:23
问题 I'm trying to set up a gruntfile that utilizes requirejs and almond. The docs suggest it should be really easy, and following their lead, I tried: requirejs: { compile: { options: { baseUrl: "tmp", mainConfigFile: "tmp/main.js", name: "../bower_components/almond/almond", out: "tmp/<%= pkg.name %>.js" } } } Unfortunately, this approach compiles almond.js rather than my actual source. Am I getting something wrong? How do I automate almond along with requirejs? 回答1: The trick is to use include:

Karma and RequireJS getting files outside base url

可紊 提交于 2019-12-07 02:11:45
问题 I am trying to configure automatic testing using karma. My file structure is as follows /assests /css /font /img /js /collection /lib /model /plugin /spec /view test-main.js main.js /templates index.html karma.conf.js karma.conf.js: module.exports = function(config) { config.set({ // base path that will be used to resolve all patterns (eg. files, exclude) basePath: '', // frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['jasmine',

grunt requirejs ignores paths from my mainConfigFile

谁说胖子不能爱 提交于 2019-12-07 01:13:57
问题 Project Intro My project is a single page storefront. The project has multiple modules, and each module contains a set of controller.js, view.js and model.js files, as well as a template.html file. And uses requirejs to manage dependencies. Problem Statement I want to use mainConfigFile to provide paths to reference modules in grunt-requirejs. Part of my mainConfigFile's require.config is stored in separate file (base.dependency.config), and require.config.paths are pieced together by

RequireJS using multiple data-main's

大憨熊 提交于 2019-12-06 21:13:28
问题 I'm using RequireJs 2.0 (or attempting to use). Currently, my assets are grouped into to parts, "General" and "Custom". All pages, should use the General scripts, while only some pages should use the Custom. From what I can tell RequireJs, accepts one data-main value which holds your config and basically your module require's. This is fine if all pages use the same assets, but how would I add an additional data-main script for Custom pages? Thank you! 回答1: Use your data-main attribute to load

Grunt & requirejs optimizer for a multi app project

你。 提交于 2019-12-06 20:58:02
问题 I'm having issues getting Grunt to perform requirejs optimization on a project with the following structure: static/js |── apps |── app.js |── dash.js |── news.js ... (many more 'app' files) |── build |── collections |── libs |── models |── util |── views Each of static/js/apps/*.js should be compiled to static/js/build/*.js containing the relevant dependencies (eg. views/view1 , libs/query etc). This is currently being performed by a basic bash script: JS_ROOT="static/js" for f in ${JS_ROOT}

Is it possible to make JavaScript module compatible with both NodeJS and RequireJS?

╄→гoц情女王★ 提交于 2019-12-06 20:52:16
问题 I have been investigating how various module concepts can be applied within NodeJS and browser applications using the the NodeJS require (obviously in NodeJS apps) and RequireJS for the web browser environment. It then dawned on me that some modules may be useful for use by both the client and server applications and thus could be reused. How can modules be developed so that they are compatible with both of these environments? One is synchronous and one asynchronous. My first thought was to

requireJs order plugin: can it exist in a different path than the require.js basePath?

谁说胖子不能爱 提交于 2019-12-06 18:43:07
问题 when using the order plugin require.js looks for it in the given basePath/order.js example: require( { baseUrl: '/public/js/' }, [ 'require', 'order!http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.1.7/underscore-min.js', 'order!http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.5.3/backbone-min.js', 'order!http://cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js' ], function (require) { require(['application'], function (app) { app.run(); }); } ); it looks for the order plugin in

JS三教九流系列-require.js-网站模块化开发

匆匆过客 提交于 2019-12-06 18:14:10
js开发的模块化就是module处理 简单理解js模块化的开发就是让我们的web项目对js进行分类的处理 我们在开发网站的时候,里面会用要很多的类库,如jquery,还会有到基于jq各种插件,还会有其他类库,还有自己写的js或者jq代码等。一个html页面会有n多个script标签对外部js的引用,是不是感觉这样的页面会非常的混乱,如果我们可以只用一个script标签载入一个js文件,这个js文件把其他需要的js文件能全部加载进去,并且按着之间依赖关系执行,是不是一个页面就非常的整洁和容易扩展处理。 js的开发规范有AMD,典型代表就是require.js CMD,典型代表就是sear.js Commonjs规范我们已经接触过,在nodejs的安装和使用中我们在页面里运用require()请求原生模块、第三方模块和export定义我们第三方模块就是在运用commonjs的规范开发 我们的requirejs就是典型的amd规范处理,实现html页面中head.appendchild("script")的加载和内部依赖顺序处理 amd是异步加载模块化开发,采用异步的载入方式,也就是我们虽然先引用了require.js,下面的js文件也可能先执行处理,如果对上面有依赖,也可能失效。 我们通过参考requriejs的手册,去实践到我们的网页开发中去,利用amd模块化的技术去开发我们的网页。

$.mustache() is defined, but Mustache isn't defined when mustache() is invoked

青春壹個敷衍的年華 提交于 2019-12-06 17:49:26
I am trying to use Mustache along with requireJS and jQuery, and it seems that it is being loaded into the browser since Chrome's console outputs correctly: >$.mustache <function (template, view, partials) { return Mustache.render(template, view, partials); } But when I try to use the mustache function it gives the error ReferenceError: Mustache is not defined and points to line 588 in the mustache.js file itself: $.mustache = function (template, view, partials) { return Mustache.render(template, view, partials); }; Here is how I'm invoking it in the main.js file: require(['mustache'],

How to call a function within the same module?

a 夏天 提交于 2019-12-06 16:52:56
I'm trying to get my head round RequireJS in order to tidy up my app. I have a few modules, and a main.js script. In my main.js, I am defining a module that contains a few AJAX functions, to make basic API calls. Inside this "API" module, I am first calling one of the AJAX functions, which after completion, needs to call a different AJAX function, inside the same "API" module (as these are Async tasks, I thought chaining them like this would be OK?!). But, just calling the function name within the same module doesn't work. So how do I call a function within the same module? Here is how my "API