Answer the question
In order to leave comments, you need to log in
Why doesn't gulp load js automatically?
Made the assembly on gulp. Everything works with CSCC and normally loads styles in './build/css/main.min.css' , but doesn't load js. In order for it to load the latest version of the code, you need to restart gulp via the console.
const gulp = require("gulp"); //gulp
const concat = require("gulp-concat"); //обьединение проектов
const autoprefixer = require("gulp-autoprefixer"); //добавляет префиксы
const cleanCSS = require('gulp-clean-css'); //минификация css
const uglify = require('gulp-uglify'); //минификация js
const del = require('del'); //обновление файлов
var browserSync = require('browser-sync').create(); // сервер
const sass = require('gulp-sass');
const rename = require('gulp-rename');
const notify = require('gulp-notify');
// порядок загрузки
const jsFiles = [
'./src/js/lib.js',
'./src/js/main.js'
]
function styles() {
return gulp.src('./src/scss/**/*.scss')
.pipe(sass({
outputStyle: 'expanded'
}).on("error", notify.onError()))
.pipe(rename({
suffix: '.min'
}))
.pipe(autoprefixer({
cascade: false,
}))
.pipe(cleanCSS({
level: 2
}))
.pipe(gulp.dest('./build/css/'))
.pipe(browserSync.stream());
}
function scripts() {
return gulp.src('./src/js/**/*.js')
.pipe(concat('all.js'))
.pipe(uglify({
toplevel: true,
}))
.pipe(gulp.dest('./build/js'))
.pipe(browserSync.stream());
}
// автообновление
function watch() {
browserSync.init({ //запуск сервака
server: {
baseDir: "./"
},
tunnel: false, // создание доступного СЕРВЕРА на своем компе. см КМ tunnel
});
gulp.watch('./src/scss/**/*.scss', styles); // следим за css
gulp.watch('./src/js/**/*.js', styles); // следим за js
gulp.watch('./*.php', browserSync.reload); // следим за html
}
function clean() {
return del(['build/*'])
}
gulp.task('scripts', scripts);
gulp.task('styles', styles);
gulp.task('watch', watch);
gulp.task('default', gulp.series(clean, gulp.parallel(scripts, styles), 'watch' ));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question