【问题标题】:gulp, build multiple projectsgulp,构建多个项目
【发布时间】:2015-05-14 17:11:31
【问题描述】:

我有一个 Gulp 构建过程,它运行大约 10 个任务,包括 browserify 和 watch。它目前构建了一个 common-bundle.js 和 common-libs.js。它使用浏览器同步来给我亚秒级的重建。

现在我还想构建一个依赖于公共项目的项目。我想保留 common 和这个项目的实时重建,以便我可以同时处理它们。我想保持构建过程本身尽可能干燥,并重用我创建的任务来构建通用。

例如,一个示例任务:

var config = require('../config');
gulp.task('styles', function () {
  return gulp.src(config.styles.src) // if i could tell it to get config elsewhere...
  ...

我不能将参数传递给每个任务来告诉它,去运行任务但是使用:

var config = require('../config').common;

对比

var config = require('../config').projectA;

我不认为任务可以接受参数。

有没有不同的方式来构建它? git/gist 链接将不胜感激。

【问题讨论】:

    标签: gulp commonjs


    【解决方案1】:

    现在我正在尝试这种方法 - 每个任务 js 文件定义了 2 个任务,但至少任务的逻辑被重用。我仍然希望有更清洁的东西。

    ./gulp/task/style.js:

    function styles(config){
       return gulp.src(config.styles.src)
          ...
       }
    }
    gulp.task('styles', function () {
       styles(config.common);
    });
    gulp.task('stylesProject1', function () {
       styles(config.project1);
    });
    

    devTask.js:

    runSequence(['styles', 'stylesProject1], 'watch', callback);
    

    【讨论】:

      猜你喜欢
      • 2015-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-23
      • 2021-05-31
      • 1970-01-01
      • 2016-03-30
      • 1970-01-01
      相关资源
      最近更新 更多