在我的应用程序中,我希望有一个环境配置,为每次部署使用不同的版本名称,以便应用程序正确缓存被破坏,并且用户的浏览器缓存中没有过时的代码版本。注意我一直在关注本指南。
因此,在 main.js 中,在我做任何事情之前,我使用通用配置调用 require.config,该配置使用当前日期/时间来破坏环境配置文件上的缓存,然后在加载环境配置后,我使用环境“config.version” 作为 urlArgs 的一部分,以保证包含新部署的代码而不是过时的版本。请注意,配置文件中的对象还有其他将在整个应用程序中使用的属性(例如谷歌分析帐号)。
如果我删除允许我设置环境/配置依赖项的第一个 require.config ,我的 r.js 构建文件似乎很好,但是当我重新添加它时,我正在使用的基础设施 JS 模块分组第三-party 脚本窒息说它找不到我的下划线库(或我在其中包含的任何库)。请注意,即使我不包括 environment/config 并且只进行两个 require.config 调用,也会产生相同的错误。两个 require.config 调用是否会导致此错误?谢谢你的帮助。
//Error:
Error: ENOENT, no such file or directory '<%root_folder%>\dist\js\underscore.js'
In module tree:
infrastructure
我的主要 JS 文件
//main.js
require.config({
baseUrl: "js",
waitSeconds: 0,
urlArgs: "bustCache=" + (new Date).getTime()
});
require(["environment/config"], function(config) {
"use strict";
require.config({
urlArgs: "bustCache=" + config.version,
baseUrl: "js",
waitSeconds: 0,
paths: {
underscore: "lib/lodash.underscore-2.4.1-min",
},
shim: {
"underscore":{
exports : "_"
}
}
});
//commented out, b/c not needed to produce the error
//require(["jquery", "infrastructure"], function($) {
//$(function() {
//require(["app/main"], function(app) {
//app.initialize();
//})
//});
//});
});
这是构建文件...
//build file
({
mainConfigFile : "js/main.js",
appDir: "./",
baseUrl: "js",
removeCombined: true,
findNestedDependencies: true,
dir: "dist",
optimizeCss: "standard",
modules: [
{
name: "main",
exclude: [
"infrastructure"
]
},
{
name: "infrastructure"
}
],
paths: {
"cdn-jquery": "empty:",
"jquery":"empty:",
"bootstrap.min": "empty:"
}
})
这里基础设施.js
define(["underscore"], function(){});
配置文件(将有更多的键,如谷歌分析帐号和其他环境特定信息。)
//config.js
define({version:"VERSION-XXXX", cdn: { jquery: "//path-to-jquery-1.11.0.min" }});
我正在运行的命令:“r.js -o build.js”