0

我使用的是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 的内容,没有包含其他必需的文件。

我在网上搜索过,看了一堆不同的例子,但没有一个对我有用。

我在这里做错了什么?

4

1 回答 1

0

对于其他尝试这样做的人,我在下载页面上迷惑了它说:

Node.js 版本可通过 npm 获得。这个包包含一个浏览器客户端的副本,它在运行时由 Faye 服务器提供。

所以要得到它,你必须通过 NPM 拉下代码,然后进入 NPM 安装目录,它位于“客户端”目录中......

于 2018-09-02T22:08:38.507 回答