代码之家  ›  专栏  ›  技术社区  ›  Ali

在vs代码中打开项目时未检测到Gulp任务

  •  0
  • Ali  · 技术社区  · 5 年前

    Gulp任务:命令失败:Gulp--Tasks simple--cwd “c:\wamp64\www\gulp_p”--gulpfile“c:\wamp64\www\gulp_p\咕噜文件.js" 必须指定函数 在吞咽集[作为设置任务](c:\wamp64\www\gulp_p\node_modules\undertaker\lib\set-任务.js:10:3个) 在吞咽任务(c:\wamp64\www\gulp_p\node_modules\undertaker\lib\任务.js:13:8个) 在对象处。(c:\wamp64\www\gulp\p\《古尔夫档案》js:64:6个) at模块。编译(内部/模块/cjs/装载机。js:956:30分) 在对象.模块.\u扩展..js(内部/模块/cj/装载机.js:973:10分) 在模块负载(内部/模块/cjs/装载机.js:812:32个) 在功能模块.\u负载(内部/模块/cjs/装载机.js:724:14) 执行时(C:\Users\alia\AppData\Roaming\npm\node_modules\gulp cli\lib\versioned“^4.0.0\索引js:36:18) { generatedMessage:false, code:'错误断言', 实际:错误, 期望值:true, 运算符:'=='}

    gulp --version => CLI version: 2.2.0  -  Local version: 4.0.2
    node --version => v12.13.0
    npm --version => 6.12.0
    npx --version => 6.12.0
    

    包.json

    {
      "name": "gulp_p",
      "version": "1.0.0",
      "main": "gulpfile.js",
      "dependencies": {
        "gulp": "^4.0.2",
        "gulp-clean": "^0.4.0",
        "gulp-clean-css": "^3.10.0",
        "gulp-concat": "^2.6.1",
        "gulp-concat-css": "^3.1.0",
        "gulp-inject": "^4.3.2",
        "gulp-install": "^1.1.0",
        "gulp-minify": "^3.1.0",
        "gulp-minify-css": "^1.2.4",
        "gulp-prompt": "^1.1.0",
        "gulp-requirejs": "^1.2.0",
        "gulp-watch": "^5.0.1"
      },
      "devDependencies": {},
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "author": "",
      "license": "ISC",
      "description": ""
    }
    

    正在工作,因为我在不同的计算机上使用它。所以没有错误咕噜文件.js它位于项目的根本

    'use strict';
    
    var gulp = require('gulp');
    
    var prompt = require('gulp-prompt');
    var log = require('fancy-log');
    var concatCss = require('gulp-concat-css');
    var minifyCSS = require('gulp-minify-css');
    var cleanCSS = require('gulp-clean-css');
    
    var concat = require('gulp-concat');
    var minify = require('gulp-minify');
    var clean = require('gulp-clean');
    
    var watch = require('gulp-watch');
    
    var theme_input='sunstar';
    
    gulp.task('css', function() {
        var importFrom = require('gulp/themes/'+theme_input+'.js');
        return gulp.src(importFrom.css_arr,{base: '.'})
          .pipe(concatCss(importFrom.destination_css))
          .pipe(minifyCSS({keepSpecialComments: 0}))
          .pipe(gulp.dest('.'));
      });
    
    gulp.task('scripts', function() {
        var importFrom = require('gulp/themes/'+theme_input+'.js');
        return gulp.src(importFrom.js_arr)
          .pipe(concat(importFrom.destination_js))
          .pipe(minify({keepSpecialComments: 0}))
          .pipe(gulp.dest('.'));
      });
    
    
    gulp.task('choose', function(){
        log('Please enter THEME name, then type of task [js/css].');
        return gulp.src('*')
        .pipe(prompt.prompt([{
            type: 'input',
            name: 'theme_input',
            message: 'Please enter THEME name?'
        },{
            type: 'input',
            name: 'task',
            message: 'Please enter task Type?'
        }], function(res){
            theme_input = res.theme_input;
            var importFrom = require('gulp/themes/'+theme_input+'.js');
            if(res.task == 'css'){
                gulp.src(importFrom.css_arr,{base: '.'})
                .pipe(concatCss(importFrom.destination_css))
                .pipe(minifyCSS({keepSpecialComments: 0}))
                .pipe(gulp.dest('.'));
            }else if(res.task == 'js'){
                gulp.src(importFrom.js_arr)
                .pipe(concat(importFrom.destination_js))
                .pipe(minify({keepSpecialComments: 0}))
                .pipe(gulp.dest('.'));
            }
        }));
    });
    
    gulp.task('default',['choose','css','scripts']);
    
    0 回复  |  直到 5 年前
        1
  •  4
  •   Mark    5 年前

    由于您使用的是gulp v4,因此该代码将不起作用:

    gulp.task('default',['choose','css','scripts']);

    改为:

    gulp.task('default',gulp.series('choose','css','scripts'));

    另一台计算机必须使用gulpv3。