你能分享一个项目之间的一个gulp框架吗?
我有很多项目都遵循特定的文件夹结构和约定。
我不想复制整个项目,而只想为每个项目configuration一个configuration对象,每个项目链接到全局框架。
例:
/gulp-framework index.js /project-a gulpfile.js configuration.js /project-b gulpfile.js configuration.js
里面的index.js
var configuration = require('configuration');
里面的configuration.js:
module.exports = function() { return { foo : true }; }
在gulp文件里面我会有:
require('./configuration'); require('../gulp-framework');
然而,运行吞咽只是给我一个错误
'找不到模块configuration'。
我想所有我想做的是传递一个configuration对象到全球框架,但没有太多的运气。
想法?
在index.js
基本上使用require('configuration')
将在/gulp-framework/node_modules/
查找configuration
模块。 它不会从project-a
或project-b
加载configuration.js
。 (更多关于require()
如何工作的确切逻辑。)
您需要显式地将configuration和gulpfile.js
对象从您的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
在index.js中 :
module.exports = function(gulp, config) { // project-independent stuff using gulp and config goes here return gulp; };