【发布时间】:2012-10-25 18:20:36
【问题描述】:
我正在尝试使用 r.js 优化我的 requireJS JavaScript 应用程序。不幸的是,它在运行“localStorage”函数(浏览器内置的 localStorage 函数)时停止。
错误信息:
ReferenceError: localStorage is not defined
发生错误的函数:
function getFromLocalStorage()
{
return localStorage.getItem('foo') ? JSON.parse(localStorage.getItem('foo')) : {};
}
如何解决此类错误?是否可以在 r.js 优化器中使用 localStore?
更多信息:
构建脚本:
({
appDir: "../",
baseUrl: "js/",
dir: "./build",
mainConfigFile: "app.js",
paths: {
jQuery: "empty:"
},
name: "app",
findNestesDependencies: true
})
应用结构:
/
---> /js (where app.js lies)
---> /app (here lies the file with the localStore-call)
---> /lib
【问题讨论】:
-
你最终在这方面取得了进展吗?
-
并非如此 - 似乎 requireJS 模块中的 reqiureJS 插件会导致问题。我切换到 UglifyJS,它基本上做同样的事情。不过感谢您的帮助!
标签: local-storage requirejs r.js