使用RequireJS和Grunt获取空白页面
Getting blank page using RequireJS and Grunt
我在这里有点疯了。我正试图使用Grunt来完成一个基于RequireJS的大型项目,并在部署过程中组合和缩小结果。以下是我的咕哝过程(使用咕哝contrib requirejs):
requirejs: {
compile: {
options: {
baseUrl: "public/js",
mainConfigFile: "public/js/config.js",
name: 'config',
out: "public/js/optimized/script.min.js",
preserveLicenseComments: false
}
}
}
最初,我把输出的脚本放在HTML中,但这导致了"define is undefined"错误,这意味着RequireJS没有被调用。因此,我在HTML中放了这样的内容:
<script data-main="js/optimized/script.min" src="js/vendor/require.js"></script>
然而,现在我只收到一张空白页。
我能找到的最接近的东西,听起来像是在这里,但现在并没有太大帮助。作为参考,我把它作为我项目的起点——然而,当我运行它时,一切似乎都对他们有效,但我找不到区别。
这是我的config.js文件:
require.config({
//Define the base url where our javascript files live
baseUrl: "js",
//Increase the timeout time so if the server is insanely slow the client won't burst
waitSeconds: 200,
//Set up paths to our libraries and plugins
paths: {
'jquery': 'vendor/jquery-2.0.3.min',
'underscore': 'vendor/underscore.min',
'backbone': 'vendor/backbone.min',
'marionette': 'vendor/backbone.marionette',
'mustache': 'vendor/mustache.min',
'bootstrap': 'vendor/bootstrap.min',
'bootbox': 'vendor/bootbox.min',
'jquery-ui': 'vendor/jquery-ui-1.10.2',
'app-ajax': '../conf/app-ajax',
'common': 'common',
'moment': 'vendor/moment.min'
},
//Set up shims for non-AMD style libaries
shim: {
'underscore': {
exports: '_'
},
'backbone': {
deps: ['underscore', 'jquery'],
exports: 'Backbone'
},
'marionette': {
deps: ['backbone', 'underscore', 'jquery'],
exports: 'Marionette'
},
'mustache': {
exports: 'mustache'
},
'bootstrap': {
deps: ['jquery']
},
'bootbox': {
deps: ['jquery', 'bootstrap'],
exports: 'bootbox'
},
'jquery-ui': {
deps: ['jquery']
},
'jquery-layout': {
deps: ['jquery', 'jquery-ui']
}
}
});
//Initalize the App right after setting up the configuration
define([
'jquery',
'backbone',
'marionette',
'common',
'mustache',
'bootbox',
'controllers/GlobalController',
'routers/GlobalRouter'
],
function ($, Backbone, Marionette, Common, Mustache, bootbox) {
//Declare ECMAScript5 Strict Mode first and foremost
'use strict';
//Define the App Namespace before anything else
var App = Common.app_namespace || {};
//Create the Marionette Application
App.Application = new Marionette.Application();
//Add wrapper region, so we can easily swap all of our views in the controller in and out of this constant
App.Application.addRegions({
wrapper: '#wrapper'
});
// Set up Initalizer (this will run as soon as the app is started)
App.Application.addInitializer(function () {
//Reach into Marionette and switch out templating system to Mustache
Backbone.Marionette.TemplateCache.prototype.compileTemplate = function (rawTemplate) {
return Mustache.compile(rawTemplate);
};
var globalController = new App.Controllers.GlobalController();
var globalRouter = new App.Routers.GlobalRouter({
controller: globalController
});
//Start Backbone History
Backbone.history.start();
});
//Start Application
App.Application.start();
}
);
好吧,这就是疯狂的简单修复:
在require.config之后声明的模块中,在声明模块时使用"require"而不是"define"。
如果你使用"define",它会添加"config"作为该模块的依赖项,这破坏了整个过程。疯狂!
相关文章:
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- jquery试图按名称获取按钮位置
- 如何在jQuery中获取元素的形式
- 如何在php文件中获取$.post-ajax传递的值
- 在Shopify中获取博客文章的图片
- 获取当前URL,替换部分路径名,然后在空白选项卡中打开
- 获取空白抓取数据
- 使用obj.style.marginTop获取页边空白顶部失败,但如果首先显式设置了marginTop,则该操作有效
- 使用RequireJS和Grunt获取空白页面
- 从一行开始直到任何内容,获取除新行之外的所有空白
- 使用JavaScript获取页边空白
- Maelstorm jquery xmlrpc获取空白错误
- Regex获取字符和空白之间的字符串,并排除第一个分隔符
- 如何让RegEx获取整个URL..从http开始,获取后面的所有内容,直到出现空白以及如何排除某些字符
- Servlet偶尔会从Javascript XHR获取空白数据
- 如何在php中使用jquery在对话框中获取文本框的值,我将其作为空白或未定义
- 获取一个空白输入字段的ID
- Javascript幻灯片问题.正在获取空白屏幕
- 为什么我的函数没有从空白输入框中获取值并正确执行函数
- 空白屏幕和必要的滚动事件,以在Sencha Touch中记录较少的商店中获取值