当我从终端运行gulp脚本时,为什么我的gulpfile.js没有编译为scripts.js?

时间:2019-10-30 02:33:08

标签: javascript jquery gulp

下面是我的gulpfile.js的副本。由于某些原因,当我从VSCode中的终端运行“ gulp脚本”时,/ util.js,/ alert.js和push.js并未编译到我的scripts.js文件中。我将不胜感激,以帮助我解决此问题的建议。我是gulpfile格式的新手,所以如果我对gulpfile格式不感到惊讶 在某处犯了错误

const gulp = require('gulp');
const sass = require('gulp-sass');
const browserSync = require('browser-sync').create();
const concat = require('gulp-concat');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');

function scripts() {
    return gulp.src(
        'node_modules/jquery/dist/jquery.js',
        'node_modules/bootstrap/js/dist/util.js',
        'node_modules/bootstrap/js/dist/alert.js',
        'node_modules/var/push.js',
        'js/main.js',
        'js/other.js'
) 
        .pipe(concat('scripts.js'))
        .pipe(gulp.dest('js'))
        .pipe(rename({suffix: '.min'}))
        .pipe(uglify())
        .pipe(gulp.dest('./js'));
}


// compile scss into css
function style() {
    // 1 where is scss file
    return gulp.src('scss/**/*.scss')
    //  2 pass  that file through sass compiler
    .pipe(sass().on('error', sass.logError)) 
    // 3 where do iI have the compiled css? 
    .pipe(gulp.dest('./css'))
    // 4 stream changes to all browsers
    .pipe(browserSync.stream());
}

function watch() {
    browserSync.init({
      server: {
          baseDir: './'
 }  
 });
    gulp.watch('scss/**/*.scss', style);
    gulp.watch('*.html').on('change', browserSync.reload);
    gulp.watch('js/**/*.js').on('change', browserSync.reload);
}


exports.style = style;
exports.watch = watch;
exports.scripts = scripts;

1 个答案:

答案 0 :(得分:0)

在将多个glob或路径传递到gulp.src时,应将它们包装在一个数组中:

return gulp.src([
    'node_modules/jquery/dist/jquery.js',
    'node_modules/bootstrap/js/dist/util.js',
    'node_modules/bootstrap/js/dist/alert.js',
    'node_modules/var/push.js',
    'js/main.js',
    'js/other.js'
])