Tag: requirejs

RequireJS是未定义的

经过很多挫折之后,我终于决定通过npm安装requirejs 。 但是,即使这个基本的例子,它仍然是行不通的。 define(function(require) { var requirejs = require('node/node/lib/node_modules/npm/node_modules/requirejs/require'); requirejs.config({ //Pass the top-level main.js/index.js require //function to requirejs so that node modules //are loaded relative to the top-level JS file. nodeRequire: require }); requirejs(['http'], function (http) { // code here }); }); 错误: TypeError: requirejs is undefined @ test.js:7 如果我只requirereplace长path,我会得到: TypeError: requirejs.config is not a […]

Node.js和Require.js包含一个完整的目录

这里有一个类似的问题,但它适用于浏览器。 我想知道在节点中使用require.js时是否可以要求目录中的每个文件。 有没有捷径,或者我不得不手动迭代文件夹中的所有文件,并要求他们一个一个?

在r.js构build文件中加载ngmin失败

我试图在requirejs的ngmin中使用ngmin ,但由于某种原因,我无法使其工作。 我已经通过全局和本地npm安装ngmin和requirejs ,这些选项都不会在onBuildRead()正确加载ngmin 。 我也导出了NODE_PATH ,但是这也没有帮助。 构build文件没有提供隔离问题的钩子函数,但我不是一个nodejs专家,所以我不知道如何进一步解决这个问题。 任何帮助表示赞赏。 ({ mainConfigFile: './static/js/boot.js', baseUrl: './static/js', name: 'boot', include: 'require.js', out: './static/js/main-built.js', normalizeDirDefines: 'all', onBuildRead: function (moduleName, path, contents) { var ngmin = require('ngmin'); console.log(ngmin); // ngmin is undefined return ngmin.annotate(contents); // no method annotate of undefined } })

如何将节点模块导入到我的backbone.js应用程序中?

我试图包围node.js模块,要求,以及如何在backbone.js应用程序中使用模块。 现在我正在使用以代码开头的快速服务器: var express = require('express'), http = require('http'), config = require("./config"), oauth = require("oauth"), bcrypt = require("bcrypt"), sqlite = require("sqlite3"), _ = require("underscore"), exec = require('child_process').exec, app = express(), server = http.createServer(app).listen( process.env.PORT || config.port); 然后我有一个定义所有视图和模型的router.js文件。 看起来像这样的config.js文件: require.config({ baseUrl: '/', paths: { 'util' : 'assets/lib/util', 'jquery' : 'assets/lib/jquery', 'underscore' : 'assets/lib/underscore', 'backbone' : 'assets/lib/backbone' […]

在客户端加载本地插件

是否有可能从客户端JavaScript使用requireJS或其他模块加载本机插件(用C / C + +编写,如nodejs)? 我正在写一个nodejs + express应用程序,它提供一个加载javascript文件的html文件。 我正在使用requireJS并将这些客户端js文件编译到AMD模块中。 我可以从nodejs服务器端的js脚本加载和调用本地方法,并想知道是否有可能从客户端js脚本做同样的事情。

在Backbone和RequireJS中使用listenTo

所以在使用RequireJS之前,我有下面的代码工作正常,并从服务器,而不是一个.fetch()调用拉从post…鉴于RequireJS的模块化模式,我不能有这个事实漂亮的app.postsvariables浮动其他文件,是否还有一种方法仍然使用$(document).ready函数,并有postsvariables仍然响应'重置'事件? 目前,我只是得到这个与.fetch(见下文)。 routes.js router.get('/fund', function(req, res) { Post.find({}, function(err, docs) { res.render('fund', { posts: docs //passed to bootstrapPosts in script element }); }); }); index.jade var bootstrapPosts = !{JSON.stringify(posts)}; collections.js app.posts = new app.PostCollection(); //app. == namespacing app.js $(document).on('ready', function() { app.post_appView = new app.postAppView(); app.posts.reset(bootstrapPosts); app.posts.fetch(); //**Don't want to use this**// }); post_appView.js initialize: […]

npm:如何使用正确的依赖关系创builddebugging和生产版本?

我正在构build一个单页面的应用程序,它使用打字稿和一些其他的依赖(jQuery的,不可变的,lodash,反应,…)。 requirejs包含不同的结果模块。 我想创builddebugging版本和生产版本,其中debugging版本应该包括依赖关系的debugging版本(例如,非缩小版本,带有debugging检查(例如React)),生产版本应该包括依赖关系的缩小生产版本。 我怎样才能做到这一点与npm(请不要咕噜咕噜,吞咽等)?

如何启动与咕噜茉莉testing?

我想创build一个咕task任务,当代码改变时自动运行茉莉花testing。 对于AMD的支持,我安装了grunt-template-jasmine-requirejs 。 我将这些行添加到我的gruntfile中: connect: { test : { port : 8000 } }, jasmine: { jasmine_tests: { src: 'src/**/*.js', options: { specs: 'spec/*Spec.js', helpers: 'spec/*Helper.js', host: 'http://127.0.0.1:8000/', template: require('grunt-template-jasmine-requirejs'), templateOptions: { requireConfigFile: 'public/js/app/config/config.js' } } } }, 现在我尝试通过inputgrunt jasmine开始我的testing。 但我得到的是这样的: 运行“jasmine:jasmine_tests”(茉莉花)任务 通过PhantomJStesting茉莉花规格 警告:PhantomJS无法加载您的网页。 使用–force继续。 由于警告而中止。 那里有什么可能是错的? 我的目录结构: – website3 – .grunt + grunt-contrib-jasmine + […]

为什么节点上的requirejs在继续之前没有加载指定的require

更新中… 即使没有asynchronous加载文件操作,它仍然不会运行我期望它根据您的解释…例如 part0_start.js … var requirejs = require('requirejs'); requirejs.config({ nodeRequire : require }); requirejs([ 'part1_setup'], function( part1_setup ) {//this callback executes when part1_setup has been compiled and run console.log( 'part1_setup callback called') }) part1_setup.js … requirejs( [ 'stopwatchObject' ], function( stopwatch ) {//run the callback function when stopwatchObject is loaded… console.log( 'stopwatch object compiled' ); […]

UMD的JavaScript模块,也在严格的模式下工作

我很难重写这个工作在“严格”模式。 由于“这个”没有明确定义,所以我在编译时遇到了jshint错误。 我在想,我的大脑只是不够抽象地想出一个创造性的解决scheme。 任何帮助,将不胜感激。 代码改编自通用模块定义Github回购: https : //github.com/umdjs/umd/blob/master/returnExports.js (function (root, factory) { if (typeof define === 'function' && define.amd) { // AMD Module define([], factory); } else if (typeof module === 'object' && module.exports) { // Node Module module.exports = factory(); } else { // Browser Global root.returnExports = factory(); } }(this, function () { […]