Почему мой gulpfile.js не компилируется в scripts.js, когда я запускаю скрипты gulp из терминала? - PullRequest
0 голосов
/ 30 октября 2019

Ниже приведена копия моего gulpfile.js. По некоторым причинам /util.js, /alert.js & push.js не компилируются в мой файл scripts.js, когда я запускаю «сценарии gulp» из терминала в VSCode. Буду признателен за совет, чтобы помочь мне разобраться с этой проблемой. Я новичок в формате 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 голосов
/ 30 октября 2019

При передаче нескольких глобусов или путей к 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'
])
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...