Node.js 您能否在项目之间共享一个gulp框架?

Node.js 您能否在项目之间共享一个gulp框架?,node.js,frameworks,gulp,shared-libraries,shared,Node.js,Frameworks,Gulp,Shared Libraries,Shared,我有许多项目都遵循特定的文件夹结构和约定 我希望每个项目都有一个配置对象,每个项目都链接到全局框架,而不是复制整个项目 例如: /gulp-framework index.js /project-a gulpfile.js configuration.js /project-b gulpfile.js configuration.js Inside index.js var configuration = require('configuration')

我有许多项目都遵循特定的文件夹结构和约定

我希望每个项目都有一个配置对象,每个项目都链接到全局框架,而不是复制整个项目

例如:

/gulp-framework
    index.js
/project-a
    gulpfile.js
    configuration.js
/project-b
    gulpfile.js
    configuration.js
Inside index.js

var configuration = require('configuration');
在configuration.js内部:

module.exports = function() {
   return { foo : true };
}
在吞咽文件中,我会:

require('./configuration');
require('../gulp-framework');
然而,大口大口大口地喝只会给我留下一个错误

“找不到模块配置”

我想我所要做的只是将一个配置对象传递给全局框架,但运气不太好


想法?

基本上使用
index.js中的
require('configuration')
将在
/gulp framework/node\u modules/
中查找
配置
模块。它不会从
project-a
project-b
加载
configuration.js
。(阅读更多关于
require()
工作原理的确切逻辑。)

您需要显式地将配置和gulp对象从
gulpfile.js
传递到
index.js

在每个gulpfile.js中:

var config = require('./configuration.js');
var gulp = require('../gulp-framework')(require('gulp'), config);

// project-specific stuff using gulp and config goes here
module.exports = function(gulp, config) {
  // project-independent stuff using gulp and config goes here

  return gulp;
};
index.js中

var config = require('./configuration.js');
var gulp = require('../gulp-framework')(require('gulp'), config);

// project-specific stuff using gulp and config goes here
module.exports = function(gulp, config) {
  // project-independent stuff using gulp and config goes here

  return gulp;
};

我想您忘记了“/”var配置=require(“/”配置”);inside index.jsNo我正在尝试引用configuration.jsNo中导出的模块。我明天将尝试这个,并根据需要阅读!Cheers这对解决这个问题非常有效,我想最后一个问题是,看看我的主框架是如何在/gulp framework下运行的,是否可以在每个项目中使用gulpfile.js,使用global node_modules文件夹?它似乎仍在寻找project-a/node_模块中的node_模块两个选项:1。2.使
project-a
成为
gulp框架的子目录