Why Gulp runs without errors but is not compiling the SCSS scripts? - gulp

I setted up my Gulpfile and so far it looked good. I had no errors anymore. Just looked a bit too fast as he compiled it. But if he would really do the job this wouldn't be any problem. But as i run my gulp css task it didn't compiled my SCSS files into CSS and also not created the minified, concatinated build file afterwards. I checked paths and searched for solutions in internet but this doesn't helped me further.
I had no errors. So why he don't do the job? Did i made a mistake in the gulpfile? I used for running the task async functions to avoid an error. But it seems it just let disappear errors but it doesn't work. Has anybody an idea what i need to change?
Thats what my console does after running gulp css:
[08:58:02] Using gulpfile C:\xampp\htdocs\united-in-faith\gulpfile.js
[08:58:02] Starting 'css'...
[08:58:02] Finished 'css' after 3.71 ms
Thats my gulpfile:
const { src, dest, watch, task, series, parallel } = require('gulp');
var sass = require('gulp-sass');
var minifyCss = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var sass = require('gulp-sass');
var browserSync = require('browser-sync').create();
var minifyPhp = require('gulp-php-minify');
var sourcemaps = require('gulp-sourcemaps');
var scssOrigin = './scripts/scss/**/_*.scss';
var jsOrigin = './scripts/js/*.js';
var cssFilePath = './scripts/css/**/_*.css';
var jsDestination = './build/scripts/js';
var cssDestination = './scripts/scripts/css';
var cssDestinationMin = './build/scripts/css';
var jsDestinationMin = './build/scripts/js';
var phpDestination = './build';
var htmlDestination = './build';
var appCssMin = 'app.min.css';
var appJsMin = 'app.min.js';
var appJs = 'app.js';
var appCss = 'app.css';
var watchJs = './scripts/js/**/_*.js';
var watchCss = './scripts/scss/**/_*.scss';
function js(done) {
src(jsOrigin)
.pipe(concat({ path: appJsMin}))
.pipe(uglify())
.pipe(dest(jsDestinationMin));
done();
}
function css(done) {
var processors = [
autoprefixer,
];
src(scssOrigin, { sourcemaps: true})
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: "expanded" }).on('error', sass.logError))
.pipe(sourcemaps.write('./maps'))
.pipe(postcss(processors))
.pipe(dest(cssDestination));
src('scripts/scss/main.scss', { sourcemaps: true})
.pipe(sass({ outputStyle: "expanded" }).on('error', sass.logError))
.pipe(dest('scripts/css'));
done();
}
function minifyCss (done) {
return src(cssFilePath, { sourcemaps: true})
.pipe(sourcemaps.init())
.pipe(minifyCss({compatibility: 'ie8'}))
.pipe(concat(appCssMin))
.pipe(sourcemaps.write('./maps'))
.pipe(dest(cssDestinationMin));
}
/*function cssNoMin (done) {
var processors = [
autoprefixer,
];
src(scssOrigin, { sourcemaps: true})
.pipe(sass({ outputStyle: "expanded" }).on('error', sass.logError))
.pipe(postcss(processors))
.pipe(dest(cssFilePath));
src(cssFilePath, { sourcemaps: true})
.pipe(concat(appCss))
.pipe(dest(scssDestinationMin))
.pipe(browserSync.stream());
done();
}
*/
function jsNoMin (done) {
src(jsOrigin)
.pipe(concat({ path: appJs }))
.pipe(dest(jsDestinationMin))
.pipe(browserSync.stream());
done();
}
function browserSyncServer (done) {
browserSync.init({
open: false,
injectChanges: true,
server: { //server variable set elsewhere
baseDir: './',
proxy: "https://localhost/united-in-faith",
port: 8080,
online: true
},
ui: {
port: 8082
}
});
done();
}
function browserSyncReload (done) {
browserSync.reload();
done();
}
function publishPhp () {
return src('sites/**/*php')
.pipe(dest(phpDestination));
src('sites/**/*html')
.pipe(dest(phpDestination));
}
function watch_files () {
watch('*.php', browserSyncReload);
watch([watchJs,watchCss], series(css,minifyCss, js, browserSyncReload))
.on('error', function (err) {
console.log(err.toString());
this.emit('end');
});
}
function watchNoMin () {
watch('*.php', browserSyncReload);
watch([watchJs,watchCss], series(css, jsNoMin , browserSyncReload))
.on('error', function (err) {
console.log(err.toString());
this.emit('end');
});
}
task("default", async function() {
series(css,minifyCss,js,browserSyncServer);
});
task("css", async function() {
series(css,minifyCss,browserSyncServer);
});
task("js", async function() {
series(js,browserSyncServer);
});
task("publish", async function() {
series(css, minifyCss,js,publishPhp,browserSyncServer);
});
task("watch", series(watch_files, browserSyncServer));
task("watch-no-min", series(watchNoMin, browserSyncServer));
task("all", parallel(css,js));
task("css-no-min", css);
task("js-no-min", js);
Thats my dependencies of Package.json
"dependencies": {
"lodash": "^4.17.21",
"#fortawesome/fontawesome-pro": "^6.0.0-beta1",
"bootstrap": "^5.0.1",
"bootstrap-icons": "^1.5.0",
"ckeditor4": "^4.16.1",
"cookieconsent": "^3.1.1",
"emojione": "^4.5.0",
"gulp-php-minify": "^0.1.3",
"jquery": "^3.6.0",
"jquery-ui": "^1.12.1",
"jquery-ui-touch-punch": "^0.2.3"
},
"devDependencies": {
"q": "^1.5.1",
"autoprefixer": "^10.2.6",
"browser-sync": "^2.26.14",
"chokidar": "^3.5.2",
"debug": "^4.3.1",
"gulp": "^4.0.2",
"gulp-clean-css": "^4.3.0",
"gulp-cli": "^2.3.0",
"gulp-concat": "^2.6.1",
"gulp-postcss": "^9.0.0",
"gulp-sass": "^4.1.0",
"gulp-sourcemaps": "^3.0.0",
"gulp-uglify": "^3.0.2",
"gulp-watch": "^5.0.1",
"webpack": "^5.40.0",
"webpack-cli": "^4.7.2"
}

Related

How to deploy project local to production server using gulp?

I want to deploy my project local to production server.
At my local machine I am using gulp build gulp serve command.
This command is redirected to me at
http://localhost:3000.
When I added code on production server and run these command.
it is redirect to me at http://142.93.165.118:3000
I want to display original host url like:https://example.com
Currently it is displaying http://142.93.165.118:3000 on production server.
Here is my gulp.js code
'use strict';
/**
The custom gulp file to build and serve the web site.
*/
//The main gulp task creator
var gulp = require('gulp'),
connect = require('gulp-connect');
//SASS transpilation to CSS
var sass = require('gulp-sass');
//Refresh the browser when the files are updated.
var browserSync = require('browser-sync').create();
//Minify JS codes
var uglify = require('gulp-uglify');
//Filter files by extension and pass them to a callback
var gulpIf = require('gulp-if');
//Minify CSS codes
var cssnano = require('gulp-cssnano');
//CSS sourcemaps to find the class definistions easily
var sourcemaps = require('gulp-sourcemaps');
//Optimize images
var imagemin = require('gulp-imagemin');
//Caches the optimized images not to optimize them with every build/run
var cache = require('gulp-cache');
//Delete the given folder contents for clean up
var del = require('del');
//Run multiple tasks concurrently
var runSequence = require('run-sequence');
//Handles AngularJS dependency injection
var ngAnnotate = require('gulp-ng-annotate');
//Renames files
var rename = require('gulp-rename');
//Injects the JS and CSS file paths into the index.html file
var inject = require("gulp-inject");
//Concat(merge) files
var concat = require('gulp-concat');
//Reads bower files from bower.json to process them
var bowerMain = require('main-bower-files');
//Filter files by extension and return the paths.
var gulpFilter = require('gulp-filter');
//Minify HTML files
var htmlmin = require('gulp-htmlmin');
//Concatenates AngugularJS templates
var angularTemplatecache = require("gulp-angular-templatecache");
//This will redirect all requests to index.html file to allow seo friendly urls like tld/sports intead of tld/#/sports
var historyApiFallback = require('connect-history-api-fallback');
var minify = "yes";
var isServe = "false";
var conf = {
srcDir: 'src/',
appStylesDir: 'src/app/',
destDir: 'dist/',
cssDestDir: 'dist/css/',
imagesDestDir: 'dist/images/',
imagesSrcDir: 'src/images/',
fontsSrcDir: ['src/fonts/*', 'bower_components/bootstrap-sass/assets/fonts/bootstrap/*', 'bower_components/bootstrap/dist/fonts/*'],
fontsDestDir: 'dist/fonts/',
jsSrcDir: 'src/app/',
jsDestDir: 'dist/scripts/'
};
var bowerConf = {
"overrides": {
"admin-lte": {
"main": [
"**/AdminLTE.css",
"**/adminlte.js",
"**/_all-skins.min.css",
"**/jquery-jvectormap-1.2.2.min.js",
"**/jquery-jvectormap-world-mill-en.js",
"**/bootstrap3-wysihtml5.all.min.js",
"**/bootstrap3-wysihtml5.min.css",
"**/slider.css",
"**/bootstrap-timepicker.min.css",
"**/iCheck/**/_all.css",
"**/iCheck/**/futurico.css",
"**/iCheck/**/polaris.css",
"**/icheck.min.js",
"**/jquery.inputmask.js",
"**/jquery.inputmask.date.extensions.js",
"**/jquery.inputmask.extensions.js"
],
"dependencies": {
"jquery": "^3.2.1",
"jquery-ui": "1.11.4",
"jquery-slimscroll": "slimscroll#^1.3.8",
"jquery-sparkline": "^2.1.3",
"bootstrap": "^3.3.7",
"font-awesome": "^4.7.0",
"moment": "^2.18.1",
"chart.js": "1.0.*",
"datatables.net": "^1.10.15",
"datatables.net-bs": "^2.1.1",
"fastclick": "^1.0.6",
"Flot": "flot#^0.8.3",
"fullcalendar": "^3.4.0",
"ion.rangeSlider": "ionrangeslider#^2.2.0",
"jvectormap": "^1.2.2",
"jquery-knob": "^1.2.13",
"morris.js": "^0.5.1",
"PACE": "pace#^1.0.2",
"select2": "^4.0.3",
"Ionicons": "ionicons#^2.0.1",
"inputmask": "jquery.inputmask#^3.3.7",
"bootstrap-colorpicker": "^2.5.1",
"bootstrap-datepicker": "^1.7.0",
"bootstrap-daterangepicker": "^2.1.25",
"bootstrap-timepicker": "^0.5.2",
"bootstrap-slider": "*"
}
},
"bootstrap": {
"main": [
"**/bootstrap.min.css",
"**/bootstrap.min.js"
]
},
"mocha": {
"ignore": true
},
"jquery-slimscroll": {
"main": "**/jquery.slimscroll.min.js"
},
"inputmask": {
"ignore": true
},
"font-awesome": {
"main": [
"**/font-awesome.min.css",
"**/fontawesome-webfont.eot",
"**/fontawesome-webfont.woff2",
"**/fontawesome-webfont.woff",
"**/fontawesome-webfont.ttf",
"**/fontawesome-webfont.svg"
]
},
"Flot": {
"main": [
"**/jquery.flot.js",
"**/jquery.flot.resize.js",
"**/jquery.flot.pie.js",
"**/jquery.flot.categories.js"
]
},
"select2": {
"main": [
"**/select2.min.css",
"**/select2.full.min.js"
]
},
"bootstrap-colorpicker": {
"main": [
"**/bootstrap-colorpicker.min.css",
"**/bootstrap-colorpicker.min.js"
]
},
"ckeditor": {
"ignore": true
}
}
};
gulp.task('bower', function () {
var jsFilter = gulpFilter('**/*.js', {restore: true});
var cssFilter = gulpFilter(['**/*.css'], {restore: true});
var fontFilter = gulpFilter(['**/*.eot', '**/*.woff', '**/*.svg', '**/*.ttf'], {restore: true});
var imageFilter = gulpFilter(['**/*.gif', '**/*.png', '**/*.svg', '**/*.jpg', '**/*.jpeg'], {restore: true});
return gulp.src(bowerMain(bowerConf))
// JS
.pipe(jsFilter)
.pipe(concat('vendor.js'))
.pipe(gulp.dest(conf.jsDestDir))
.pipe(uglify())
.pipe(rename("vendor.min.js"))
.pipe(gulp.dest(conf.jsDestDir))
.pipe(jsFilter.restore)
// CSS
.pipe(cssFilter)
.pipe(concat('vendor.css'))
.pipe(cssnano())
.pipe(sourcemaps.write('.'))
.pipe(rename("vendor.min.css"))
.pipe(gulp.dest(conf.cssDestDir))
.pipe(cssFilter.restore)
// FONTS
.pipe(fontFilter)
.pipe(gulp.dest(conf.fontsDestDir))
.pipe(fontFilter.restore)
// IMAGES
.pipe(imageFilter)
.pipe(gulp.dest(conf.imagesDestDir))
.pipe(imageFilter.restore)
});
//JS operations
gulp.task('js', function () {
return gulp.src([
conf.jsSrcDir + '/app.js',
conf.jsSrcDir + '/core/**/*.js',
conf.jsSrcDir + '/pages/**/*.js',
conf.jsSrcDir + '/modules/**/*.js',
conf.jsSrcDir + '**/*.html'
])
.pipe(gulpIf('*.html', htmlmin({
removeEmptyAttributes: true,
removeAttributeQuotes: true,
collapseBooleanAttributes: true,
collapseWhitespace: true
})))
.pipe(gulpIf('*.html', angularTemplatecache('templateCacheHtml.js', {
module: 'adminlte',
root: 'app'
})))
.pipe(concat("app.js"))
.pipe(ngAnnotate())
//.pipe(gulpIf(minify === 'yes', uglify()))
.pipe(rename("app.min.js"))
.pipe(gulp.dest(conf.jsDestDir))
});
//SASS operations
gulp.task('sass', function () {
return gulp.src(
[
conf.srcDir + "index.scss",
conf.appStylesDir + '**/**/*.scss'
])
.pipe(concat("app.css"))
.pipe(sass().on('error', sass.logError)) // log errors to console
.pipe(gulpIf(minify === 'yes', cssnano())) //Minify
.pipe(rename('app.min.css'))
.pipe(gulp.dest(conf.cssDestDir)) // Save in the given folder
});
//INJECT operations
gulp.task('inject', function () {
return gulp.src('src/index.html')
//Remove dist from the link of the css and js files.
.pipe(inject(gulp.src(conf.cssDestDir + 'vendor.min.css', {read: false}), {
ignorePath: 'dist/',
starttag: '<!-- bower:css -->',
endtag: '<!-- endbower:css -->'
}))
.pipe(inject(gulp.src(conf.cssDestDir + 'app.min.css', {read: false}), {
ignorePath: 'dist/',
starttag: '<!-- app:css -->',
endtag: '<!-- endapp:css -->'
}))
.pipe(inject(gulp.src(conf.jsDestDir + (isServe === "yes" ? 'vendor.js' : 'vendor.min.js'), {read: false}), {
ignorePath: 'dist/',
starttag: '<!-- bower:js -->',
endtag: '<!-- endbower:js -->'
}))
.pipe(inject(gulp.src(conf.jsDestDir + 'app.min.js', {read: false}), {
ignorePath: 'dist/',
starttag: '<!-- app:js -->',
endtag: '<!-- endapp:js -->'
}))
.pipe(gulp.dest(conf.destDir));
});
// Watchers
gulp.task('watch', function () {
gulp.watch('src/app/**/*.scss', ['sass', browserSync.reload]);
gulp.watch('src/app/**/*.html', ['js', browserSync.reload]);
gulp.watch('src/app/**/*.js', ['js', browserSync.reload]);
});
// Start browserSync server
gulp.task('browserSync', function () {
browserSync.init({
server: {
baseDir: 'dist',
livereload: true,
index: 'index.html',
middleware: [historyApiFallback()]
}
});
});
gulp.task('images', function () {
return gulp.src(conf.imagesSrcDir + '**/*.+(png|jpg|jpeg|gif|svg|ico)')
// Caching images
.pipe(cache(imagemin({
interlaced: true
})))
.pipe(gulp.dest(conf.imagesDestDir))
});
//Copy fonts
gulp.task('fonts', function () {
return gulp.src(conf.fontsSrcDir)
.pipe(gulp.dest(conf.fontsDestDir))
});
//Clean up
gulp.task('clean', function () {
return del.sync('dist').then(function (cb) {
return cache.clearAll(cb);
});
});
gulp.task('clear', () =>
cache.clearAll()
);
gulp.task('clean:dist', function () {
console.log("clean dist should backup the current dist folder when build called");
return del.sync(['dist/**/*', '!dist/images', '!dist/images/**/*']);
});
gulp.task('serve', function (callback) {
minify = "no";
isServe = "yes";
runSequence(
['sass', 'js'],
['inject'],
['watch', 'browserSync'],
callback
)
});
gulp.task('connect', function() {
connect.server({
root: 'app',
livereload: true
});
});
gulp.task('default', ['connect']);
var onError = function (err) {
console.log(err);
};
var gulp = require('gulp');
var webserver = require('gulp-webserver');
gulp.task('build', function (callback) {
runSequence(
'clean:dist',
'sass',
'js',
'bower',
['images', 'fonts'],
['inject'],
callback
)
});
Could you provide me proper way.
step 1) I have moved all files of dist folder to root directory.
step 2) Deleted dist folder
step 3) run index.html
its working for me

the broswer cannot reload when files updates using gulp and browser-sync

I have total followed the instructions of https://browsersync.io/docs/gulp
my gulpfile.js code:
let gulp = require('gulp');
let sass = require('gulp-sass');
let browserSync = require('browser-sync').create();
let reload = browserSync.reload;
gulp.task('server', ['css'], function() {
browserSync.init({
server: {
baseDir: './dist'
}
});
gulp.watch('src/sass/*.scss', ['css']);
gulp.watch("dist/*.html").on('change', reload);
gulp.watch("dist/sass/*.css").on('change', reload);
});
// 编译Sass
gulp.task('css', function() { // 任务名
return gulp.src('src/sass/a.scss') // 目标 sass 文件
.pipe(sass()) // sass -> css
.pipe(gulp.dest('dist/sass/')) // 目标目录
// .pipe(reload({stream: true}))
.pipe(browserSync.stream());
});
gulp.task('default', ['server']);
when I update the sass file, it seems that the css file will be updated immediately, but the broswer cannot reload.
and the command line show:
It seem that the cli cannot connect to the broswer?
===
The problem is solved,my html file does not have a body tag,see https://github.com/BrowserSync/browser-sync/issues/392#issuecomment-245380582
I post you my GULP FILE ... as you can see i use the
gulp-webserver
it only need to put reload:true to work as you aspect:
"use strict";
var gulp = require("gulp"),
concat = require("gulp-concat"),
cssmin = require("gulp-cssmin"),
htmlmin = require("gulp-htmlmin"),
uglify = require("gulp-uglify"),
merge = require("merge-stream"),
del = require("del"),
bundleconfig = require("./bundleconfig.json"); // make sure bundleconfig.json doesn't contain any comments
var livereload = require('gulp-livereload');
var changed = require('gulp-changed');
var stripDebug = require('gulp-strip-debug');
var minifyHTML = require('gulp-minify-html');
var autoprefix = require('gulp-autoprefixer');
var minifyCSS = require('gulp-minify-css');
var rename = require('gulp-rename');
var jshint = require('gulp-jshint');
var shell = require('gulp-shell');
var sass = require('gulp-sass');
var preprocess = require('gulp-preprocess');
var ngAnnotate = require('gulp-ng-annotate');
var templateCache = require('gulp-angular-templatecache');
var webserver = require('gulp-webserver'); //<-- YOU HAVE TO INSTALL IT MAYBE WITH NPM (npm install --save -dev gulp-webserver)
// THESE IS THE TASK FOR WEB SERVER AND RELOAD
gulp.task('webserver', function () {
gulp.src('')
.pipe(webserver({
host: 'localhost', // <-- IF YOU PUT YOUR IP .. YOU CAN WATCH IT FROM OTHER devices
port: 80,
livereload: true,
directoryListing: true,
open: true,
fallback: 'index-dev.html'
}));
});
// Task to process Index page with different include ile based on enviroment
gulp.task('html-dev', function () {
return gulp.src('Index.html')
.pipe(preprocess({ context: { NODE_ENV: 'dev', DEBUG: true } })) //To set environment variables in-line
.pipe(rename({ suffix: '-dev' }))
.pipe(gulp.dest(''));
});
// Task to process Index page with different include ile based on enviroment
gulp.task('html-prod', function () {
return gulp.src('Index.html')
.pipe(preprocess({ context: { NODE_ENV: 'prod', DEBUG: false } })) //To set environment variables in-line
.pipe(rename({ suffix: '-prod' }))
.pipe(gulp.dest(''));
});
// CSS concat, auto-prefix, minify, then rename output file
gulp.task('minify-css', function () {
var cssPath = { cssSrc: ['./app/view/assets/content/css/styles-default.css', './app/view/assets/content/css/styles-theme-1.css', './app/view/assets/content/css/styles-theme-2.css', '!*.min.css', '!/**/*.min.css'], cssDest: './app_build/content_build/css' };
return gulp.src(cssPath.cssSrc)
// .pipe(shell(['attrib C:/_goocity/Goocity/Goocity.Web/app_build/content_build/css/*.css -r']))
// .pipe(concat('styles.css'))
.pipe(autoprefix('last 2 versions'))
.pipe(minifyCSS())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(cssPath.cssDest));
});
// Lint Task
gulp.task('lint', function () {
var jsPath = { jsSrc: ['./app/app.js', './app/controller/*.js', './app/view/utils/directives/*.js', './app/model/services/*.js'] };
return gulp.src(jsPath.jsSrc)
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
//SASS task
gulp.task('sass', function () {
var sassPath = {
cssSrc: ['./app/view/assets/content/css/*.scss'], cssDest: './app/view/assets/content/css'
};
gulp.src(sassPath.cssSrc)
.pipe(shell(['attrib C:/_goocity/Goocity/Goocity.Web/app/view/assets/content/css/*.css -r']))
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(sassPath.cssDest))
.pipe(livereload());
});
gulp.task('cache', function () {
return gulp.src('./app/view/template/**/*.html')
.pipe(templateCache('templates.js', { module: 'Goocity', root: '/app/view/template' }))
.pipe(gulp.dest('./app/view/template'))
.pipe(livereload());
});
gulp.task('cache-directives', function () {
return gulp.src('./app/view/utils/directives/template/**/*.html')
.pipe(templateCache('templates.js', { module: 'Goocity', root: '/app/view/utils/directives/template' }))
.pipe(gulp.dest('./app/view/utils/directives/template'))
.pipe(livereload());
});
gulp.task("min:js", function () {
var tasks = getBundles(".js").map(function (bundle) {
return gulp.src(bundle.inputFiles, { base: "." })
.pipe(ngAnnotate({
remove: true,
add: true,
single_quotes: false
}))
.pipe(concat(bundle.outputFileName))
.pipe(uglify())
.pipe(gulp.dest("."));
});
return merge(tasks);
});
//gulp.task("min:css", function () {
// var tasks = getBundles(".css").map(function (bundle) {
// return gulp.src(bundle.inputFiles, { base: "." })
// .pipe(concat(bundle.outputFileName))
// .pipe(cssmin())
// .pipe(gulp.dest("."));
// });
// return merge(tasks);
//});
gulp.task("min:html", function () {
var tasks = getBundles(".html").map(function (bundle) {
return gulp.src(bundle.inputFiles, { base: "." })
.pipe(concat(bundle.outputFileName))
.pipe(htmlmin({ collapseWhitespace: true, minifyCSS: true, minifyJS: true }))
.pipe(gulp.dest("."));
//.pipe(livereload());
});
return merge(tasks);
});
gulp.task("clean", function () {
var files = bundleconfig.map(function (bundle) {
return bundle.outputFileName;
});
return del(files);
});
gulp.task("min", ["clean", "min:js", "minify-css", 'html-dev', "cache", "cache-directives"]);
gulp.task("default", ["watch", "webserver"]);
gulp.task("watch", function () {
livereload.listen();
// watch for JS error
gulp.watch(['./app/app.js', './app/controllers/*.js', './app/directives/*.js', './app/services/*.js'], ['lint']);
// min js
getBundles(".js").forEach(function (bundle) {
gulp.watch(bundle.inputFiles, ["min:js"]);
});
//watch for SASS changes
gulp.watch('./app/view/assets/content/css/scss/*.scss', ['sass']);
gulp.watch('./app/view/assets/content/css/scss/settings/*.scss', ['sass']);
gulp.watch('./app/view/assets/lib/bower/lumx/dist/scss/base/*.scss', ['sass']);
gulp.watch('./app/view/assets/lib/bower/lumx/dist/scss/modules/*.scss', ['sass']);
gulp.watch('./app/view/assets/content/css/*.scss', ['sass']);
gulp.watch('./app/view/assets/content/css/Hover-master/scss/*.scss', ['sass']);
//gulp.watch('./app/view/assets/content/css/*.css', ['minify-css']);
//watch for PREPROCCESS x PROD
gulp.watch('Index.html', ['html-prod']);
//watch for PREPROCCESS x DEV
gulp.watch('Index.html', ['html-dev']);
//watch for TEMPLATE CACHE
gulp.watch('./app/view/template/**/*.html', ['cache']);
gulp.watch('./app/view/utils/directives/template/**/*.html', ['cache-directives']);
});
function getBundles(extension) {
return bundleconfig.filter(function (bundle) {
return new RegExp(extension).test(bundle.outputFileName);
});
}
The problem is solved,my html file does not have a body tag,see https://github.com/BrowserSync/browser-sync/issues/392#issuecomment-245380582

Gulp watch don't overwrite files

When I launch gulp generates me the files, but when it enters the watch mode, understands that there was a change but does not overwrite files:
My gulp sample
var argv = require('yargs').argv;
var gulp = require('gulp');
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');
var dependencies = [
'core-js/client/*.min.js',
'zone.js/dist/zone.js',
'reflect-metadata/Reflect.js',
'systemjs/dist/system.src.js',
'rxjs/**/*.js',
'#angular/**/*.js',
'angular2-in-memory-web-api/*.js',
];
var modules = [
// Example: 'iconv-lite/**/*',
];
........
gulp.task("javascript", () => {
return gulp.src([
'./bower_components/jquery/dist/jquery.min.js',
'./bower_components/bootstrap/dist/js/bootstrap.min.js',
])
.pipe(gulp.dest("./build/js"))
});
gulp.task('styles', () => {
var postcss = require('gulp-postcss');
var autoreset = require('postcss-autoreset');
var simplevars = require('postcss-simple-vars');
var nested = require('postcss-nested');
var lost = require('lost');
var cssnext = require('postcss-cssnext');
var processors = [
simplevars(),
nested(),
lost(),
cssnext(),
];
return gulp.src([
'./src/css/*.css',
'./bower_components/openSans/openSans.css',
'./bower_components/components-font-awesome/css/font-awesome.min.css',
'./bower_components/bootstrap/dist/css/bootstrap.min.css',
])
.pipe(postcss(processors))
.pipe(gulp.dest('./build/css'));
});
gulp.task('ts', ['ts-app', 'ts-electron']);
gulp.task('build', ['templates', 'resources', 'styles', 'ts', 'libs', 'modules', 'images', 'javascript']);
gulp.task('watch', ['build'], () => {
gulp.watch('./src/app/**/*', ['ts-app']);
gulp.watch('./src/electron/**/*', ['ts-electron']);
gulp.watch('./src/resources/**/*', ['resources']);
gulp.watch('./src/css/**/*', ['styles']);
gulp.watch('./src/templates/**/*', ['templates']);
gulp.watch('./src/img/**/*', ['images']);
gulp.watch('./src/js/**/*', ['javascript']);
});
Platform: Win7x64
NPM: 3.10.8
NODE: v6.7.0
Gulp version:
{
"gulp": "^3.9.1",
"gulp-if": "^2.0.1",
"gulp-postcss": "^6.1.1",
"gulp-pug": "^3.0.3",
"gulp-typescript": "^2.13.6",
"gulp-uglify": "^1.5.4",
}
I also tried to manually put gulp.dest("./build/", {overwrite: true})(in all gulp.dest) but nothing change :/
What can I do to better understand the problem?

How to use vue.js with gulp?

I'm working with a small project using gulp and I want to learn about vue.js, so I want to use vue.js in this project, but I don't know how to configure vue.js in the gulpfile.js
I want to know how to configure gulpfile to use vue.js
My gulpfile.js
var env = require('minimist')(process.argv.slice(2)),
gulp = require('gulp'),
gutil = require('gulp-util'),
plumber = require('gulp-plumber'),
jade = require('gulp-jade'),
browserify = require('gulp-browserify'),
browserSync = require('browser-sync'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
gulpif = require('gulp-if'),
stylus = require('gulp-stylus'),
jeet = require('jeet'),
rupture = require('rupture'),
koutoSwiss = require('kouto-swiss'),
prefixer = require('autoprefixer-stylus'),
modRewrite = require('connect-modrewrite'),
imagemin = require('gulp-imagemin'),
karma = require('gulp-karma'),
cache = require('gulp-cache'),
rsync = require('rsyncwrapper').rsync;
// Call Jade for compile Templates
gulp.task('jade', function () {
return gulp.src('src/templates/*.jade')
.pipe(plumber())
.pipe(jade({pretty: !env.p}))
.pipe(gulp.dest('build/'));
});
gulp.task('copy', function() {
return gulp.src(['src/*.html', 'src/*.txt'])
.pipe(gulp.dest('build/'))
});
// Call Uglify and Concat JS
gulp.task('js', function () {
return gulp.src('src/js/**/*.js')
.pipe(plumber())
.pipe(concat('main.js'))
.pipe(gulpif(env.p, uglify()))
.pipe(gulp.dest('build/js'));
});
// Call Uglify and Concat JS
gulp.task('browserify', function () {
return gulp.src('src/js/main.js')
.pipe(plumber())
.pipe(browserify({debug: !env.p}))
.pipe(gulpif(env.p, uglify()))
.pipe(gulp.dest('build/js'));
});
// Call Stylus
gulp.task('stylus', function () {
gulp.src('src/styl/main.styl')
.pipe(plumber())
.pipe(stylus({
use:[koutoSwiss(), prefixer(), jeet(), rupture()],
compress: env.p,
}))
.pipe(gulp.dest('build/css'));
});
// Call Imagemin
gulp.task('imagemin', function () {
return gulp.src('src/img/**/*')
.pipe(plumber())
.pipe(cache(imagemin({optimizationLevel: 3, progressive: true, interlaced: true})))
.pipe(gulp.dest('build/img'));
});
// Call Watch
gulp.task('watch', function () {
gulp.watch('src/templates/**/*.jade', ['jade']);
gulp.watch('src/styl/**/*.styl', ['stylus']);
gulp.watch('src/js/**/*.js', [(env.fy) ? 'browserify' : 'js']);
gulp.watch('src/img/**/*.{jpg,png,gif}', ['imagemin']);
});
gulp.task('browser-sync', function () {
var files = [
'build/**/*.html',
'build/css/**/*.css',
'build/img/**/*',
'build/js/**/*.js',
];
browserSync.init(files, {
server: {
baseDir: './build/',
},
});
});
// Rsync
gulp.task('deploy', function () {
rsync({
ssh: true,
src: './build/',
dest: 'user#hostname:/path/to/www',
recursive: true,
syncDest: true,
args: ['--verbose'],
},
function (erro, stdout, stderr, cmd) {
gutil.log(stdout);
});
});
// Default task
gulp.task('default', [(env.fy) ? 'browserify' : 'js', 'jade', 'copy', 'stylus', 'imagemin', 'watch', 'browser-sync']);
// Build and Deploy
gulp.task('build', [(env.fy) ? 'browserify' : 'js', 'jade', 'copy', 'stylus', 'imagemin', 'deploy']);
Vueify is a browserify transform; gulp-browserify isn't maintained anymore but I assume that you can still add vueify as a transform once it's installed:
gulp.task('browserify', function () {
return gulp.src('src/js/main.js')
.pipe(plumber())
.pipe(browserify({
debug: !env.p,
transform: ['vueify']
}))
.pipe(gulpif(env.p, uglify()))
.pipe(gulp.dest('build/js'));
});
Check this out:
This is a package which lets you setup gulp task for vue.js.
https://www.npmjs.com/package/gulp-vueify
Using:
.pipe(babel({presets: ['es2015']}))
On a normal gulp task helped me concat and uglify my vue.js files.
If this is what you meant, then you will also need to install babel with npm and add:
var babel = require('gulp-babel');

Gulp - how to delete build directory before running other tasks

I got this Gulp file where I'm running various tasks.
I would like to delete the contents of my build directory before running any other tasks but can't work out how to do this.
I've tried lots of various ways I found when searching for a solution to this but can't get it to work.
Here is my Gulp file:
// List required plugins
var gulp = require('gulp'),
del = require('del'),
uglify = require('gulp-uglify'),
postcss = require('gulp-postcss'),
lost = require('lost'),
nano = require('gulp-cssnano'),
sourcemaps = require('gulp-sourcemaps'),
autoprefixer = require('autoprefixer'),
mqpacker = require('css-mqpacker'),
mixins = require('postcss-mixins'), // Must go before other plugins in the PostCSS task
nested = require('postcss-nested'),
vars = require('postcss-simple-vars'),
partials = require('postcss-import'),
plumber = require('gulp-plumber'),
gutil = require('gulp-util'),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
browserSync = require('browser-sync').create();
// Config - Paths and other config
var src = {
cssDir: 'src/css/**/*.css',
jsDir: 'src/js/**/*.js',
imgDir: 'src/img/*',
svgDir: 'src/img/svg/**/*.svg',
htmlDir: 'src/**/*.html',
srcDir: 'src/',
},
build = {
buildDir: 'build/',
cssDir: 'build/assets/css/',
htmlDir: 'build/**/*.html',
jsDir: 'build/assets/js/',
imgDir: 'build/assets/img/',
},
options = {
autoprefix: { browsers: ['last 2 versions'] },
imagemin: { optimizationLevel: 7, progressive: true, interlaced: true, svgoPlugins: [ {removeViewBox: false}, {cleanupIDs: false} ], use: [pngquant()] },
port: '80',
};
// Error handling function
// Thanks to https://cameronspear.com/blog/how-to-handle-gulp-watch-errors-with-plumber/
var onError = function(err) {
gutil.beep();
console.log(err);
this.emit('end');
}
// Clean task
gulp.task('clean:build', function () {
return del([
build.buildDir,
]);
});
// Copy HTML to Build
gulp.task('html', function () {
return gulp.src(src.htmlDir)
.pipe(plumber({
errorHandler: onError
}))
.pipe(gulp.dest(build.buildDir))
.pipe(browserSync.stream());
});
// BrowserSync Server + watching files for changes
gulp.task('server', function() {
browserSync.init({
server: {
baseDir: build.buildDir
},
port: options.port,
});
});
// PostCSS Task
gulp.task('css', function () {
var processors = [
partials(),
lost(),
autoprefixer({ browsers: ['last 2 version'] }),
mixins(),
nested(),
vars(),
mqpacker(), // Make sure mqpacker is last!
];
return gulp.src(src.cssDir)
.pipe(plumber({
errorHandler: onError
}))
.pipe(sourcemaps.init())
.pipe(postcss(processors))
//.pipe(nano()) - Disable minification during development
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(build.cssDir))
.pipe(browserSync.stream());
});
// JS Task
gulp.task('compressJS', function() {
return gulp.src(src.jsDir)
.pipe(plumber({
errorHandler: onError
}))
.pipe(uglify())
.pipe(gulp.dest(build.jsDir))
.pipe(browserSync.stream());
});
// Image Task
gulp.task('imagemin', function() {
return gulp.src(src.imgDir)
.pipe(plumber({
errorHandler: onError
}))
.pipe(imagemin(
options.imagemin
))
.pipe(gulp.dest(build.imgDir))
.pipe(browserSync.stream());
});
gulp.task('watch', function () {
gulp.watch(src.cssDir, ['css']);
gulp.watch(src.jsDir, ['compressJS']);
gulp.watch(src.htmlDir, ['html']);
gulp.watch(src.imgDir, ['imagemin']);
});
gulp.task('default', ['html', 'imagemin', 'compressJS', 'server', 'watch']);
How should I do to run the task clean:build before any other tasks but only run it once. Or is there a better way of cleaning out files before running a build?
Thanks!!
Have your tasks depend on your clean task:
gulp.task('html', ['clean:build'], function() { ... })
this is how i do it.
var del = require('del') ;
gulp.task('delete-build-folder', function(cb) {
return del([config.buildDir], cb);
});
gulp.task('default', ['delete-build-folder'], function() {
console.log('building.....');
gulp.start('copy-html', 'copy-html-views');
});