最近我发现了 Flux 架构,发现了这个,React starter kit。良好的结构,但是,应用程序需要为浏览器编译,从带有 gulp 的 node.js。
我正在使用reqwest对服务器进行 ajax 调用, reqwest 需要 window ,这在 node.js 上不可用。当我从 ES 6 编译(使用gulp-render)到 ES 5.1 时,react render 会评估所有require(..)文件并因为未定义窗口而给我错误,我该如何避免这种情况?你有没有处理过这样的事情?
events.js:72
throw er; // Unhandled 'error' event
^
ReferenceError: window is not defined
at E:\projects\micaimportanta\node_modules\reqwest\reqwest.js:13:13
at win (E:\projects\micaimportanta\node_modules\reqwest\reqwest.js:8:72)
at Object.<anonymous> (E:\projects\micaimportanta\node_modules\reqwest\reqwest.js:11:2)
at Module._compile (module.js:456:26)
at Module._extensions..js (module.js:474:10)
at reactTransform (E:\projects\micaimportanta\gulpfile.js:65:5)
at Object.Plugin.reactTransform (E:\projects\micaimportanta\node_modules\gulp-render\index.js:72:7)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)