- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 require.js 构建了一个 Web 应用程序,并成功使用 r.js 将所有模块定义合并到一个文件中。
创建 r.js 优化文件后,我希望能够单独请求优化文件,但在加载和定义模块后它无法执行任何代码:
require([
'app1/optimizedAppFile'
], function (optimizedApp) {
//optimizedApp is undefined, even though it loaded
//the file and executed the module definitions in debugger
});
通过在 require.config.js 中定义优化文件的顶级模块的路径,然后在 main.js 中 require 来加载/实例化应用程序是否合适?即
requirejs.config({
paths: {
'optimizedApp.topLevelModule' : 'app1/optimizedAppFile'
//optimizedApp.topLevelModule is the full module name
//app1/optimizedAppFile is the combined file from r.js
}
});
最佳答案
是的,通过 rjs 优化代码后,您可以只需要该文件。
但是,我今天也遇到了这个问题。经过几个小时的调试,我发现当前的 1.1.2 主干版本有一段代码检测 AMD 是否存在(“define”函数存在)。
删除后,主干看起来像这样
// Backbone.js 1.1.2
// (c) 2010-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
// Backbone may be freely distributed under the MIT license.
// For all details and documentation:
// http://backbonejs.org
(function(root, factory) {
root.Backbone = factory(root, {}, root._, (root.jQuery || root.Zepto || root.ender || root.$));
}(this, function(root, Backbone, _, $) {
所以基本上我所做的就是使其全局可访问并为其添加填充
require.config({
baseUrl: "/static/src/scripts/js",
paths: {
jquery: 'vendors/jquery/jquery',
underscore: 'vendors/underscore/underscore',
backbone: 'vendors/backbone/backbone',
marionette: 'vendors/backbone/backbone.marionette'
},
shim: {
jquery: {
exports: "jQuery"
},
underscore: {
exports: "_"
},
backbone: {
deps: ['underscore', 'jquery'],
exports: 'Backbone'
},
marionette: {
deps: ['backbone'],
exports: 'Marionette'
}
}
});
检查元素并检查您的控制台,看看它提示什么,以及优化的轮次通过将 rjs 的优化选项设置为 false 并查找出错的部分。
关于javascript - requirejs:需要 r.js 优化文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23248478/
如何使用 requirejs 导入 recaptcha。我已经尝试了几件事,但没有任何效果。 我需要这样做,以便能够在加载后使用 reCaptcha 的渲染方法自行渲染它。 require.confi
我正在尝试将 OpenLayers 库与 RequireJS 一起使用。 问题是,OpenLayers 一直处于“未定义”状态,即使它被列为我的模块的唯一依赖项: define(['OpenLayer
我正在尝试使用 gulp-requirejs构建一个演示项目。我希望结果是一个包含所有 js 依赖项和模板的单个文件。这是我的 gulpfile.js var gulp = require('gulp
没有 Require.js 就可以在浏览器控制台中调用全局对象,例如 app app.movies 当我将代码包装在 RequireJS 模块中时,如何在浏览器控制台中访问模块中的数据?我会发现这有助
这个问题有 3 个部分。我有两个模块 a 和 b。 如何在最初需要 b 后重新定义它? 如果 a 依赖于 b,我该如何更新 a 以使用新的 b? 如何找到所有依赖于 b 的模块并更新它们? 例如;
我正在尝试找到一种将 Backbone-relational 子模型与 RequireJS 一起使用的方法,其中子模型与 super 模型位于不同的文件中。 例如: // app.js define(
使用 require.js (r.js) 优化 js 代码时,将所有 js 源代码复制到目标目录(dir 属性)。 有没有办法(一些配置)来防止 requirejs 复制源文件? 最佳答案 如果添加
main.js 文件中的代码如下: phantom.injectJs("libs/require-1.0.7.js"); require.config( {
我在 require-config.js 中配置了一些路径,如下所示: var require = { baseUrl: '/javascript', paths: {
我正在重构一个大型 javascript 代码库以使用 RequireJS。不幸的是,我正在处理的许多文件都不是面向对象的,并且在不进行重大修改的情况下无法返回对象。是否有更有效的方法让“依赖”模块访
我是 RequireJS 的新手,我对加载顺序感到困惑。 我有一个全局项目配置,需要在位于 js/app/* 的模块之前加载。 这是我的结构: index.html config.js js/
我已经使用 requireJS 设置了一个 Angular 应用程序。在部署之前,我将所有内容捆绑到一个唯一的文件中。通常,外部库没有 requireJS“定义”包装器。 例如Angular Para
假设我有一个如下所示的模块: define(['jquery', 'actions', 'util', 'text!../templates/dialog.html!strip', 'text!../
如何使用 grunt-contrib-requirejs配置或什至r.js Config不缩小特定文件。 我可以使用optimize: 'none'选项禁用所有文件的缩小。但我不知道如何对单个文件禁用
好吧,我已经知道你应该像这样使用 RequireJS 配置路径 require.config({ paths: { name: 'value' } }); 并这样调用它。 requir
我希望能够有选择地定义一个模块,然后在我的代码中使用或不使用它。我正在考虑的特殊情况是在调试/测试环境中加载模拟/ stub 模块,但不是在我上线时加载。这是示例: 在 html 文件中,可以选择加载
我为构建过程创建了一个任务,其中 requirejs 作为它的子任务之一,并且在 requirejs 之后几乎没有其他任务。该任务在运行 requirejs 后停止,即使使用详细信息也不会抛出错误。任
我想创建一个可以从我的 RequireJS 项目中的任何模块访问的变量。 例如,在初始化时我想设置: this.myVar = 123; 并且能够在我的 RequireJS 项目内部(但不是外部)的任
我正在使用 TypeScript、Backbone 和 Mustache 编写网络应用程序。我想使用 Requirejs 进行依赖加载。 我还在使用 TypeScript 的 Web Essentia
我正在尝试创建一个节点样板,并尝试创建一个任务来运行 Jasmine 测试。我的 Gruntfile.js 中有以下配置: jasmine: { src : ['static/test/spec/
我是一名优秀的程序员,十分优秀!