我使用FayeJS并且已修改最新版本以使用RequireJS,因此不再有单个文件链接到浏览器。相反,结构如下:
/adapters
/engines
/mixins
/protocol
/transport
/util
faye_browser.js
我使用以下nodejs构建脚本尝试最终将上述所有内容缩小为单个文件:
var fs = require('fs-extra'),
requirejs = require('requirejs');
var config = {
baseUrl: 'htdocs/js/dev/faye/'
,name: 'faye_browser'
, out: 'htdocs/js/dev/faye/dist/faye.min.js'
, paths: {
dist: "empty:"
}
,findNestedDependencies: true
};
requirejs.optimize(config, function (buildResponse) {
//buildResponse is just a text output of the modules
//included. Load the built file for the contents.
//Use config.out to get the optimized file contents.
var contents = fs.readFileSync(config.out, 'utf8');
}, function (err) {
//optimization err callback
console.log(err);
});
faye_browser.js的内容是:
'use strict';
var constants = require('./util/constants'),
Logging = require('./mixins/logging');
var Faye = {
VERSION: constants.VERSION,
Client: require('./protocol/client'),
Scheduler: require('./protocol/scheduler')
};
Logging.wrapper = Faye;
module.exports = Faye;
正如我所说,优化器应该提取所需的文件,然后如果这些文件有所需的文件,它应该拉入那些......,并输出一个包含整个批次的缩小的faye.min.js,重构,因此不需要额外的服务器端调用。
faye.min.js会被创建,但它只包含faye_browser.js的内容,不包含任何其他必需的文件。
我在网上搜索过,看了一堆不同的例子,但没有一个适合我。
我在这做错了什么?
对于其他试图这样做的人,我在下载页面上说它:
Node.js版本可以通过npm获得。此程序包包含浏览器客户端的副本,该副本在运行时由Faye服务器提供。
所以为了得到它你必须通过NPM下拉代码,然后进入NPM安装目录,它在“客户端”目录...