Gulp Gulp 任务的多个来源

g6ll5ycj  于 2022-12-08  发布在  Gulp
关注(0)|答案(2)|浏览(167)

I am trying to accomplish a few tasks that I feel like should be relatively basic but I am having a really hard time figuring what I am doing wrong.
I need to:

  1. lint javascript that I have written,
  2. concat javascript that I have written with 3rd party javascript downloaded via NPM,
  3. uglify it
    I store paths in my package.json file, so I have this for my app libraries:
{
  ...,
  "paths": {
    "src": {
      "js": "./src/js/",
      "appLibraries": [
        "./node_modules/jquery/dist/jquery.js",
        "./node_modules/slick-carousel/slick/slick.js"
    },
    "dist": {
      "js": "./build/js"
    }
  }
}

I have a simple jshint function:

function lintScripts() {
    return gulp
        .src( pkg.paths.src.js + '**/*.js' )
        .pipe( $.jshint() )
        .pipe( $.jshint.reporter( 'jshint-stylish' )
}

This works fine. My function to actually compile my JS:

function scripts() {
    lintScripts();

    return gulp
    .src( pkg.paths.src.js + '**/*.js', pkg.paths.src.appLibraries )
    // do my other stuff
    .pipe( gulp.dest( pkg.paths.dist.js )
}

When I do this, I only get the first argument actually processed. I've tried swapping the src line for this: .src([ pkg.paths.src.js + '**/*.js', pkg.paths.src.appLibraries ]) since I know it can accept an array, but apparently it can't accept an array of arrays because I get this error: Invalid glob argument after ./src/js/**/*.js
I can get around this by updated my package.json paths to the following, but this seems silly and redundant:

{
  ...,
  "paths": {
    "src": {
      "js": "./src/js/",
      "appLibraries": [
        "./node_modules/jquery/dist/jquery.js",
        "./node_modules/slick-carousel/slick/slick.js",
        "./src/js/**/*.js"
    },
    "dist": {
      "js": "./build/js"
    }
  }
}

What am I missing???

xggvc2p6

xggvc2p61#

除了您提供的代码中有几处拼写错误外,如果我将数组(pkg.paths.src.appLibraries)放在第一位,然后展开该数组,并将整个内容放入数组中,如以下所示:
.src( [...pkg.paths.src.appLibraries, pkg.paths.src.js + '**/*.js'] )
不要问我为什么这些改变会带来不同-我查看了gulpjs问题和src文档,没有发现任何表明有必要这样做的东西。我建议你自己在那里提交一个问题,但是它可能会搁置一段时间。
也许gulp.src可以接受一个数组或者一个字符串,但不能两者都接受。文档在这一点上可以更正式一些...
您可以随时在以后添加src,如下所示:

function scripts() {

  return gulp

  .src(pkg.paths.src.js + '**/*.js')
    .pipe(gulp.src(pkg.paths.src.appLibraries))
    .pipe( gulp.dest( pkg.paths.dist.js ))
};
0aydgbwb

0aydgbwb2#

我从来没有用"正确"的方法解决过这个问题,但是我为任何有同样问题的人所做的是,我创建了一个变量来从我的package.json中获取数组,然后将我的新字符串推到它的末尾。

相关问题