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

问题描述 投票:0回答:1

下面是我的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;
javascript jquery gulp
1个回答
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'
])
© www.soinside.com 2019 - 2024. All rights reserved.