我使用的是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 的内容,没有包含其他必需的文件。
我在网上搜索过,看了一堆不同的例子,但没有一个对我有用。
我在这里做错了什么?