I have gulp installed and this is the error that I get. Can someone help me out please?
I have tried deleting the node_modules and did the npm-install. But it still doesnt work.
This is how my gulpfile looks like.
var gulp = require('gulp');
var gutil = require('gulp-util');
var browserify = require('browserify');
var babelify = require('babelify');
var scssify = require('scssify');
var source = require('vinyl-source-stream');
var path = require('path');
var spawn = require('child_process').spawn;
var gls = require('gulp-live-server');
var commandLineArgs = require('command-line-args');
var sass = require('gulp-sass') ;
var notify = require("gulp-notify") ;
var bower = require('gulp-bower');
var runSequence = require('run-sequence');
var lodash = require('lodash');
var config = {
sassPath: './gssp/client/style',
bowerDir: './bower_components'
};
function onError(error) {
gutil.log(error.message);
console.log(error.toString());
}
var cli = commandLineArgs([
{ name: 'packages', alias: 'p', type: String, defaultValue: [""], multiple:true }
]);
var options = cli.parse();
gulp.task('bower', function() {
return bower()
.pipe(gulp.dest(config.bowerDir))
});
gulp.task('icons', function() {
return gulp.src(config.bowerDir + '/font-awesome/fonts/**.*')
.pipe(gulp.dest('./dist/fonts'));
});
gulp.task('embeddedIcons', function() {
return gulp.src('./gssp/src/leafs/icon/fonts/**.*')
.pipe(gulp.dest('./dist/src/leafs/icon/fonts'));
});
gulp.task('css',['bower'], function() {
return gulp.src(config.sassPath + '/*.scss')
.pipe(sass({
outputStyle: 'compressed',
includePaths: [
'./gssp/client/style',
config.bowerDir + '/bootstrap-sass/assets/stylesheets',
config.bowerDir + '/font-awesome/scss',
]
})
.on('error', sass.logError))
.pipe(gulp.dest('./dist/css'));
});
gulp.task('runLiveServer', function () {
var server = gls.new(['gssp/index.js', options.packages.join(" ")]);
server.start();
gulp.watch(['./core/**/*.js','./gssp/**/*.scss'], ['build']);
gulp.watch(['./dist/bundle.js'], function (file) {
server.notify.apply(server, [file]);
});
});
gulp.task('copyStatics', function() {
return gulp.src('./core/server/public/**/*.*')
.pipe(gulp.dest('./dist'));
});
gulp.task('build',['copyStatics', 'icons', 'embeddedIcons', 'css'], function () {
return browserify({
entries: './gssp/client/index.js',
extensions: ['.jsx', '.js'],
debug: true
})
.transform("babelify", {presets: ["es2015", "react", "stage-0"]})
.bundle()
.on('error', onError)
.pipe(source('bundle.js'))
.pipe(gulp.dest('./dist'));
});
gulp.task('run-wrapper', function(done) {
var server = spawn('node', ['serviceWrapper.js'], {stdio: ['inherit']});
server.stderr.on('data', function(data){
process.stderr.write(data);
});
server.stdout.on('data', function(data) {
process.stdout.write(data);
});
server.unref();
});
gulp.task('run', function(done) {
console.log(lodash.concat);
var child = spawn('node', lodash.union(['gssp/index.js'], options.packages), {stdio: ['inherit']});
child.stderr.on('data', function(data){
process.stderr.write(data);
});
child.stdout.on('data', function(data) {
process.stdout.write(data);
});
});
gulp.task('watch', function() {
gulp.watch('./gssp/src/**/*.{js,jsx}', ['build']);
gulp.watch('./gssp/src/**/*.scss', ['build']);
});
gulp.task('serve', function(done) {
runSequence('build', ['run-wrapper', 'runLiveServer'],done)
});
gulp.task('start', function(done) {
runSequence('build', ['run-wrapper', 'run'], done);
});
gulp.task('default', ['start']);
This is how my bower file looks like.
{
"name": "gssp-sales",
"main": "index.js",
"version": "0.6.0",
"authors": [
"Vamshi Gudipati"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"bootstrap-sass": "bootstrap-sass-official#~3.3.6",
"font-awesome": "fontawesome#~4.5.0"
}
}
I have gulp installed and this is the error that I get. Can someone help me out please?
I have tried deleting the node_modules and did the npm-install. But it still doesnt work.
This is how my gulpfile looks like
Open up your font-awesome.css file in dist/css and see in the first block #font-face where the src is pointing to. Make sure it is pointing to the correct directory where you have extracted the font-awesome fonts and the error will go away.
For me I had to do something like this in my gulpfile:
gulp.task('build-fonts', function(){
return gulp.src(config.bowerDir + '/font-awesome/fonts')
.pipe(gulp.dest('./dist/fonts'));
})
Related
i have a problem with at localhost. I use gulp server for my project and i want to display img but when i use localhost it doesn't display but when i open my index.html file it works fine
<img src="src/img/logo.png" alt="Logo">
I can't find a good src to display it. How it should looks like?
edit:
my gulpfile is:
const gulp = require("gulp");
const sass = require("gulp-sass");
const sourcemaps = require('gulp-sourcemaps');
var connect = require('gulp-connect');
gulp.task('connect', function(cb) {
connect.server({
root: './dist',
livereload: true
});
cb();
});
gulp.task("sass", function() {
return gulp.src('./src/scss/main.scss')
.pipe(sourcemaps.init())
.pipe(sass({errLogToConsole: true}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./dist/css'))
.pipe(connect.reload());
});
gulp.task('html', function () {
return gulp.src('./src/*.html')
.pipe(gulp.dest('./dist'))
.pipe(connect.reload());;
});
gulp.task('watch', function () {
gulp.watch('./src/scss/**/*.scss', gulp.series('sass'));
gulp.watch('./src/**/*.html', gulp.series('html'));
});
gulp.task('default', gulp.series('connect', 'watch'));
Based on your gulp configuration your HTML files from src are moved (Part 1) into your ./dist/ folder and then served from there (Part 2). So move your index.html into src and remove it from the img tag.
Moving HTML to dist folder (Part 1):
gulp.task('html', function () {
return gulp.src('./src/*.html')
.pipe(gulp.dest('./dist'))
.pipe(connect.reload());;
});
Gulp server on dist folder (Part 2):
gulp.task('connect', function(cb) {
connect.server({
root: './dist',
livereload: true
});
cb();
});
So what you need is either a task that moves your images as well or the easy way:
Create a img folder in dist containing the image and change the path in your index.html as follows:
<img src="img/logo.png" alt="Logo">
I would recommend to change your gulp config, so it serves from your src folder for development and create a second task for a build process (Including minify css, js and moving the files). I just add a config that i used some time ago:
var gulp = require('gulp');
var sass = require('gulp-sass');
var browsersync = require("browser-sync").create();
var babel = require('gulp-babel');
var sourcemaps = require('gulp-sourcemaps');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var plumber = require('gulp-plumber');
var cssnano = require('gulp-cssnano');
var imagemin = require('gulp-imagemin');
var cache = require('gulp-cache');
var del = require('del');
var rev = require('gulp-rev');
var revdel = require('rev-del');
var collect = require('gulp-rev-collector');
// Development Tasks
// -----------------
// BrowserSync
function browserSync(done) {
browsersync.init({
server: {
baseDir: "./src/"
},
port: 3000
});
done();
}
// BrowserSync Reload
function browserSyncReload(done) {
browsersync.reload();
done();
}
// Watchers
function watchFiles(){
gulp.watch('src/scss/**/*.scss', gulp.series('sassify', browserSyncReload));
gulp.watch('src/*.html', gulp.series(browserSyncReload));
gulp.watch('src/js/**/*.js', gulp.series(browserSyncReload));
}
// Optimization Tasks
// ------------------
// Sassify
gulp.task('sassify', (cb) => {
gulp.src('src/scss/**/*.scss') // Gets all files ending with .scss in src/scss and children dirs
.pipe(plumber())
.pipe(sass()) // Passes it through a gulp-sass, log errors to console
.pipe(gulp.dest('src/css')) // Outputs it in the css folder
.pipe(browsersync.stream());
cb();
});
// Optimizing CSS
gulp.task('css', (done) => {
gulp.src('src/css/*.css')
.pipe(plumber())
.pipe(cssnano())
.pipe(gulp.dest('dist/css'));
done();
});
// Optimizing JS
gulp.task('js', (cb) => {
gulp.src('src/js/*.js')
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['#babel/env']
}))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist/js'));
cb();
});
// HTML
gulp.task('html', (cb) => {
gulp.src('src/*.html')
.pipe(gulp.dest('dist'));
cb();
});
// Optimizing Images
gulp.task('images', function(done) {
gulp.src('src/assets/**/*.+(png|jpg|jpeg|gif|svg)')
// Caching images that ran through imagemin
.pipe(cache(imagemin({
interlaced: true,
})))
.pipe(gulp.dest('dist/assets'))
done();
});
// Generate Revisions...
gulp.task('revision:rename', function(){
gulp.src(["dist/**/*.css",
"dist/**/*.js"])
.pipe(rev())
.pipe(revdel())
.pipe(gulp.dest('dist'))
.pipe(rev.manifest({ path: 'manifest.json' }))
.pipe(gulp.dest('dist'))
});
// update references
gulp.task('revision:updateReferences', function(){
gulp.src(['dist/manifest.json','dist/**/*.{html,json,css,js}'])
.pipe(collect())
.pipe(gulp.dest('dist'))
});
// Cleaning
gulp.task('clean', function() {
return del.sync('dist').then(function(cb) {
return cache.clearAll(cb);
});
})
gulp.task('clean:dist', (cb) => {
del.sync(['dist/**/*', '!dist/assets', '!dist/assets/**/*']);
cb();
});
// Build Sequences
// ---------------
gulp.task('default',
gulp.series(
'sassify',
gulp.parallel(
watchFiles,
browserSync
)
)
);
gulp.task('build',
gulp.series(
'clean:dist',
'sassify',
gulp.parallel(
'css',
'js',
'images'
),
'html'
)
);
I'm using Zurb panini to do templating and construct pages. I'm not sure where I did wrong. Now if I update my scss files, the BrowserSync will reload and the update will show. But it just doesn't work when I update html files. Could anyone help me to take a look my Gulp config? Thx~
var gulp = require('gulp');
var panini = require('panini');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var autoprefixer = require('autoprefixer-core');
var clean = require('gulp-clean');
gulp.task('copy', function() {
return gulp.src('./src/assets/icon/*')
.pipe(gulp.dest('./dist/assets/icon'));
});
gulp.task('sass', function(){
var processors = [
autoprefixer({browsers:['last 2 versions']})
];
return gulp.src('./src/assets/sass/*.scss')
.pipe(sass())
.pipe(concat('style.css'))
.pipe(gulp.dest('./dist/assets'))
});
gulp.task('clean', function () {
return gulp.src('./dist/*.html', {read: false})
.pipe(clean());
});
gulp.task('pages', function() {
return gulp.src('src/pages/**/*.html')
.pipe(panini({
root: 'src/pages/',
layouts: 'src/layouts/',
partials: 'src/partials/',
}))
.pipe(concat('index.html'))
.pipe(gulp.dest('./dist'));
});
gulp.task('browserSync', function(){
browserSync.init({
server: "./dist"
});
});
gulp.task('watch', function(){
gulp.watch(['./src/{layouts,partials}/**/*'], [panini.refresh]);
gulp.watch("./src/assets/sass/**/*.scss", ['sass']).on('change', browserSync.reload);
gulp.watch("./src/**/*.html").on('change', browserSync.reload);
});
gulp.task('build', ['clean', 'copy', 'sass', 'pages']);
gulp.task('default', ['build', 'watch', 'browserSync']);
//gulp 4.0.2 panini 1.6.3
gulp.task('compile-html', function(){
var paniniOption = {
root: 'src/html/pages/',
layouts: 'src/html/layouts/',
partials: 'src/html/includes/',
helpers: 'src/html/helpers/',
data: 'src/html/data/'
}
return gulp.src('src/html/pages/**/*.html')
.pipe(panini(paniniOption))
.pipe(gulp.dest('_site'));
});
gulp.watch('src/html/pages/**/*').on('change', gulp.series('compile-html', browserSync.reload));
gulp.watch('src/html/{layouts,includes,helpers,data}/**/*').on('change', gulp.series(async () => { await panini.refresh() }, 'compile-html', browserSync.reload));
Html file is synchronize and working, but CSS file not. Gulp and Browser sync are working too and not giving any error. I've read a documentation from official BrowserSync website but it doesn't work. Please help me. Here's my gulpfile.js file:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
var gulp = require('gulp');
// POST CSS PLUGINS
var postcss = require('gulp-postcss');
var mixins = require('postcss-mixins');
var postcssimport = require('postcss-partial-import');
var nested = require('postcss-nested');
var vars = require('postcss-simple-vars');
var lost = require('lost');
var rucksack = require('rucksack-css');
var cssnano = require('cssnano');
var autoprefixer = require('autoprefixer');
var mqpacker = require('css-mqpacker');
// OTHER PLUGINS
var pug = require('gulp-pug');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var plumber = require('gulp-plumber');
var browserSync = require('browser-sync');
// POSTCSS TASK
gulp.task('css', function() {
var plugins = [
autoprefixer({
browsers: ['last 2 version']
}),
rucksack({
alias: false,
easings: false,
inputPseudo: false
}),
lost,
mixins,
postcssimport,
nested,
vars,
mqpacker
// cssnano uncomment this when you need to minify .css files
];
return gulp.src('app/styles/*.css')
.pipe(plumber())
.pipe(postcss(plugins))
.pipe(plumber.stop())
.pipe(gulp.dest('dist/css'))
.pipe(browserSync.stream());
});
// PUG TASK
gulp.task('pug', function(){
return gulp.src('app/pug/*.pug')
.pipe(plumber())
.pipe(pug({
pretty: true // Don't minify .html files
}))
.pipe(plumber.stop())
.pipe(gulp.dest('app'))
});
// IMAGE MINIFICATION TASK
gulp.task('img-min', function() {
gulp.src('app/images/**/*')
.pipe(imagemin({
interlaced: true,
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest('dist/img'))
});
// BROWSER SYNC TASK
gulp.task('browserSync', ['css'], function() {
browserSync.init({
server: './app',
open: false,
notify: false,
logPrefix: 'ʕ•ᴥ•ʔ'
});
});
// WATCHING FILE TASK
gulp.task('watch', ['browserSync', 'css', 'pug', 'img-min'], function() {
gulp.watch("app/*.html").on('change', browserSync.reload);
gulp.watch("app/styles/*.css", ['css'], browserSync.reload);
gulp.watch('app/pug/**/*.pug', ['pug']);
});
gulp.task('default', ['watch']);
I'm trying to give Gulp a try for the first time and can't figure out why is taking so long in loading packages and running tasks, about 48 seconds every time. Not sure how many packages are the average, but I think I need all of them. I've been trying to improve the performance by following some examples but I'm stuck in the same place.
I'd really appreciate any piece of advice!
This is my gulpfile.js:
var gulp = require('gulp'),
runSequence = require('run-sequence'),
templateCache = require('gulp-angular-templatecache'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
rename = require("gulp-rename")
browserify = require('browserify'),
concat = require('gulp-concat'),
addStream = require('add-stream'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
imagemin = require('gulp-imagemin'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
ngAnnotate = require('gulp-ng-annotate'),
uglify = require('gulp-uglify'),
jshint = require('gulp-jshint'),
htmlmin = require('gulp-html-minifier'),
del = require('del');
function templates() {
return gulp.src('./app/views/**/*.html')
.pipe(templateCache({
module: 'portfolio'
}));
}
gulp.task('clean:dist', function() {
return del.sync('dist/assets/');
});
gulp.task('jshint', function() {
return gulp.src('./app/js/**/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'))
});
gulp.task('browserify', function() {
return browserify('./app/app.js')
.bundle()
.pipe(source('main.js'))
.pipe(buffer())
.pipe(ngAnnotate())
.pipe(addStream.obj(templates()))
.pipe(concat('main.js'))
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('./dist/assets/js/'))
});
gulp.task('sass', function() {
return gulp.src('./app/css/main.scss')
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(autoprefixer())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('./dist/assets/css'))
});
gulp.task('images', function() {
return gulp.src('./app/img/**/*.{png,jpg,gif,svg}')
.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
.pipe(gulp.dest('./dist/assets/img'))
});
gulp.task('copyfonts', function() {
gulp.src('./app/css/fonts/**/*.*')
.pipe(gulp.dest('./dist/assets/fonts'));
});
gulp.task('copy-index-html', function() {
gulp.src('./app/index.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('./dist'));
});
gulp.task('serve', function() {
browserSync({
server: {
baseDir: './dist'
}
});
gulp.watch('app/js/**/*.js', ['browserify', reload]);
gulp.watch('app/css/**/*.scss', ['sass', reload]);
gulp.watch('app/views/**/*.html', [reload]);
});
gulp.task('bs-reload', function () {
browserSync.reload();
});
gulp.task('default', function(callback) {
runSequence('clean:dist', 'jshint', ['browserify', 'sass', 'images','copy-index-html','copyfonts'], 'serve', callback);
});
Gulp performance (image link)
I'm having issues trying to generate sourcemaps for my CSS files.
My current stack is:
Gulp
Stylus
Autoprefixer
There are two compiling steps:
Gulp pre-compiles to CSS;
Autoprefixer post-compiles the CSS to add browser vendor prefixes;
I can't generate the sourcemaps on the first compilation, as the second one will add new lines to the CSS, and I'm quite lost on how to make them "talk" with each other.
This is what I got so far.
var gulp = require('gulp');
var paths = {
src: 'src',
dist: 'dist'
};
// ---------------------------------------
// STYLUS
var stylus = require('gulp-stylus');
var rename = require('gulp-rename');
gulp.task('stylus', ['clean:css'], function () {
return gulp.src(paths.src + '/stylus/*.styl')
.pipe(stylus({
compress: true,
sourcemap: {
inline: true,
sourceRoot: '.',
basePath: paths.dist + '/css'
}
}))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(paths.dist + '/css'));
});
// ---------------------------------------
// BROWSERSYNC
var browserSync = require('browser-sync');
// Sets up a static server
gulp.task('browser-sync', function() {
return browserSync({
server: {
baseDir: './'
}
});
});
// ---------------------------------------
// AUTOPREFIXER
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var concat = require('gulp-concat');
gulp.task('autoprefixer', ['stylus'], function () {
return gulp.src(paths.dist + '/css/*.css')
.pipe(autoprefixer())
.pipe(sourcemaps.init({
loadMaps: true
}))
.pipe(sourcemaps.write('.', {
includeContent: false,
sourceRoot: '.'
}))
.pipe(gulp.dest(paths.dist + '/css'))
.pipe(browserSync.reload({stream:true}));
});
// ---------------------------------------
// CLEAN
var del = require('del');
gulp.task('clean:css', function (cb) {
return del([
paths.dist + '/**/*.css',
paths.dist + '/**/*.map'
], cb);
});
// ---------------------------------------
// WATCH
gulp.task('watch', ['browser-sync'], function() {
gulp.watch(paths.src + '/stylus/**/*.styl', ['clean:css', 'stylus', 'autoprefixer']);
gulp.watch('*.html', ['compress', browserSync.reload]);
});