I'm having a go at setting up my own gulp file. My gulp file is:
Turning SCSS -> CSS.
Minifying JS.
And watching my files.
Finally, when I run my gulp command in terminal, (which runs all the tasks above), I want to also see any errors on watch, in my JS and SCSS file.
Let's say I'm typing JavaScript and I've made an error, I'd like to see that flagged up in my terminal.
I've tried installed jshint and jscs. And I'm not getting any node errors when I run gulp. But if I deliberately type incorrect JS, in my js file, I don't see any errors flagged up in terminal.
Here's my gulpfile.js below.
What am I doing wrong? (I have looked at many stackoverflows, but there seem to be many approaches).
var gulp = require('gulp');
var cssnano = require('gulp-cssnano');
const sass = require('gulp-sass')(require('sass'));
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
const sourcemaps = require('gulp-sourcemaps');
const browserSync = require('browser-sync').create();
// gulp sass
gulp.task('sass', function(){
return gulp.src('GULP-TEST/SCSS/style.scss')
.pipe(sass())
.pipe(cssnano())
.pipe(sourcemaps.init())
.pipe(gulp.dest('dist/css'));
});
// gulp js
gulp.task('js', function(){
return gulp.src(['GULP-TEST/js/*.js'])
.pipe(concat('all.js'))
.pipe(sourcemaps.init())
.pipe(sourcemaps.write())
.pipe(uglify())
.pipe(gulp.dest('dist'));
});
// gulp detecterror
gulp.task('detecterror', function(){
return gulp.src(['GULP-TEST/js/*.js'])
.pipe(jshint())
.pipe(jscs())
.pipe(jshint.reporter('jshint-stylish',{
verbose:true
}));
});
// gulp watch
gulp.task('watch', function() {
gulp.watch('GULP-TEST/SCSS/style.scss', gulp.series('sass')).on('change', browserSync.reload);
gulp.watch('GULP-TEST/js/*.js', gulp.series('js')).on('change', browserSync.reload);
});
// gulp
gulp.task("default", gulp.series('sass', 'js', 'watch', 'detecterror'));
Here's also my package.json as an FYI:
{
"name": "RV",
"version": "1.0.0",
"description": "Test",
"main": "index.js",
"scripts": {
"test": "test"
},
"repository": {
"type": "git",
"url": "http://code.xx.xx.xx/xx/xx.git"
},
"author": "RV",
"license": "ISC",
"devDependencies": {
"#babel/core": "^7.17.5",
"#babel/preset-env": "^7.16.11",
"browser-sync": "^2.27.7",
"gulp": "^4.0.2",
"gulp-jscs": "^4.1.0",
"gulp-jshint": "^2.1.0",
"gulp-sass": "^5.1.0",
"gulp-sourcemaps": "^3.0.0",
"gulp-uglify": "^3.0.2",
"jshint": "^2.13.4",
"jshint-stylish": "^2.2.1",
"sass": "^1.49.9"
},
"dependencies": {
"gulp-babel": "^8.0.0",
"gulp-cli": "^2.3.0",
"gulp-concat": "^2.6.1",
"gulp-cssnano": "^2.1.3"
}
}
Related
I am using gulp and browser-sync for the local development. The problem is that browser-sync (or gulp) caches the js and css resources even after i changed them. After pressing hard refreshes many times (5-7) then I can see the new code. I also tried gulp-cache to clear it but it didn't work.
package.son
{
"version": "1.0.0",
"main": "index.js",
"scripts": {
"watch": "gulp watch",
"build": "gulp build",
"build-prod": "NODE_ENV='production' gulp build --env production"
},
"babel": {
"presets": [
"#babel/env"
]
},
"browserslist": [
"last 3 version",
"> 1%",
"IE 11"
],
"author": "",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.27.10",
"browserify": "^17.0.0",
"gulp": "^4.0.2",
"gulp-babel": "^8.0.0",
"gulp-cache": "^1.1.3",
},
}
Here is the gulpfile.js
const gulp = require("gulp");
const tap = require("gulp-tap");
const log = require("gulplog");
const cache = require("gulp-cache");
/// JS transformation
const sourcemaps = require("gulp-sourcemaps");
const browserify = require("browserify");
const babelify = require("babelify");
const buffer = require("vinyl-buffer");
const uglify = require("gulp-uglify");
const browserSync = require("browser-sync").create();
const production = environments.production;
/// COMMON
const targetClassesDestination = "...";
function browserReloadTask(done) {
browserSync.reload();
done();
}
function clearCache(done) {
gulp.task("clearCache", () => cache.clearAll());
done();
}
/// JS tasks
const jsSources = "...";
function copyJsModern(done) {
gulp
.src(jsSources, { read: false })
.pipe(
tap(function (file) {
log.info("bundling " + file.path);
file.contents = browserify({ entries: file.path, debug: true })
.transform(babelify, { presets: ["#babel/env"] })
.bundle();
})
)
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(production(uglify()))
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest(targetClassesDestination));
done();
}
function watching_files() {
browserSync.init({
proxy: "localhost:8080",
});
gulp.watch(
jsSources,
gulp.series(clearCache, copyJsModern, browserReloadTask)
);
}
gulp.task("watch", watching_files);
gulp.task(
"build",
gulp.series( copyJsModern)
);
gulp.task("default", gulp.series("watch"));
I've a problem with gulp and browserify. I want minify my index.js but he's import a figure.js with import 'swiper'. And Swiper contains "import" and "export" too.
My package.json
{
"name": "gulp-frontend-kit",
"version": "2.0.0",
"description": "Gulp boilerplate front-end dev Archriss",
"author": "Archriss",
"dependencies": {
"cookies-js": "^1.2.3",
"custom-event-polyfill": "^1.0.7",
"element-qsa-scope": "^1.0.1",
"html-truncate": "^1.2.2",
"lightgallery.js": "^1.0.1",
"node-fetch": "^3.2.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"swiper": "^8.2.2",
"tingle.js": "^0.16.0",
"tippy.js": "^6.3.7"
},
"devDependencies": {
"#babel/cli": "^7.17.10",
"#babel/core": "^7.18.5",
"#babel/plugin-proposal-class-properties": "^7.17.12",
"#babel/plugin-transform-runtime": "^7.18.5",
"#babel/preset-env": "^7.18.2",
"#babel/preset-react": "^7.17.12",
"#babel/register": "^7.15.3",
"autoprefixer": "^10.4.7",
"babel-eslint": "^10.1.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-env": "^1.7.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babelify": "^10.0.0",
"browserify": "^17.0.0",
"css-mqpacker": "^7.0.0",
"cssnano": "^5.1.11",
"del": "^6.1.1",
"eslint": "^8.17.0",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-standard": "^5.0.0",
"gulp": "^4.0.0",
"gulp-buffer": "0.0.2",
"gulp-clean-css": "^4.3.0",
"gulp-combine-mq": "^0.4.0",
"gulp-concat": "^2.6.0",
"gulp-imagemin": "^7.1.0",
"gulp-livereload": "^4.0.2",
"gulp-postcss": "^9.0.1",
"gulp-sass": "^5.1.0",
"gulp-sourcemaps": "^3.0.0",
"gulp-stylelint": "^13.0.0",
"gulp-terser": "^2.1.0",
"gulp-uglify": "^3.0.2",
"gutil": "^1.6.4",
"imagemin-pngquant": "^9.0.2",
"node-sass": "^7.0.1",
"postcss-markdown": "^1.2.0",
"sass": "^1.52.3",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^2.0.0"
},
"scripts": {
"start": "gulp",
"watch": "gulp watch",
"build": "gulp build"
},
"browserify": {
"transform": [
[
"babelify",
{
"presets": [
"#babel/preset-env"
]
}
]
]
}
}
My .babelrc
{
"presets": [
"#babel/react" ,
"#babel/env" ,
],
"plugins": [
"#babel/plugin-proposal-class-properties"
]
}
My gulpfile.babel.js
const {src, dest, watch, series, parallel} = require('gulp'),
browserify = require('browserify'),
buffer = require('vinyl-buffer'),
concat = require('gulp-concat'),
livereload = require('gulp-livereload'),
source = require('vinyl-source-stream'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify'),
babelify = require("babelify")
const FILENAMES = {jsCode: 'app.js', jsVendor: 'vendor.js'};
const PATHS = {
dest: {
global: './dist',
imgFolder: 'img',
prodFolder: 'prod',
devFolder: 'dev'
},
src: {
assets: ['src/assets/**', '!src/assets/{img,img/**}'],
html: 'src/html/*.html',
img: 'src/assets/img/**/*',
jsCode: ['src/js/**/*.js', '!src/js/{vendor,vendor/**}'],
jsEntry: 'src/js/index.js',
jsVendor: 'src/js/vendor/*.js',
scss: 'src/scss/**/*.scss'
}
};
function html() {
return src(PATHS.src.html).pipe(livereload());
}
function JSVendor(isDev) {
const targetFolder = isDev === true ? PATHS.dest.devFolder : PATHS.dest.prodFolder;
return src(PATHS.src.jsVendor)
.pipe(concat(FILENAMES.jsVendor))
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('./'))
.pipe(dest(PATHS.dest.global + '/' + targetFolder))
.pipe(livereload());
}
function JSCode(isDev) {
const targetFolder = isDev === true ? PATHS.dest.devFolder : PATHS.dest.prodFolder;
return (
browserify({
entries: [PATHS.src.jsEntry],
// Pass babelify as a transform and set its preset to #babel/preset-env
transform: [babelify.configure({presets: ["#babel/preset-env"]})]
})
// Bundle it all up!
.bundle()
// Source the bundle
.pipe(source("bundle.js"))
// Then write the resulting files to a folder
.pipe(dest(PATHS.dest.global + '/' + PATHS.dest.devFolder))
);
}
function catchJSErrors(err) {
if (err instanceof SyntaxError) {
console.log('Syntax Error');
console.log(err.message);
console.log(err.codeFrame);
} else {
console.log('Error', err.message);
}
this.emit('end');
}
exports.dev = function () {
const isDev = true;
watch(PATHS.src.html, html);
watch(PATHS.src.jsVendor, JSVendor(isDev));
watch(PATHS.src.jsCode, JSCode(isDev));
};
exports.build = function () {
const devOptions = {type: 'changed'};
};
exports.default = series(html);
And My error
$ gulp dev
[17:58:49] Requiring external module #babel/register
[17:58:50] Using gulpfile E:\docker\images\XXX\web\themes\custom\XXX\front\gulpfile.babel.js
[17:58:50] Starting 'dev'...
[17:58:51] 'dev' errored after 1.13 s
[17:58:51] Error:
E:\docker\images\XXX\web\themes\custom\XXX\front\node_modules\swiper\swiper.esm.js:13
export { default as Swiper, default } from './core/core.js';
^
ParseError: 'import' and 'export' may appear only with 'sourceType: module'
at formatError (C:\Users\XXX\AppData\Roaming\npm\node_modules\gulp-cli\lib\versioned\^4.0.0\format-error.js:21:10)
at Gulp.<anonymous> (C:\Users\XXX\AppData\Roaming\npm\node_modules\gulp-cli\lib\versioned\^4.0.0\log\events.js:33:15)
at Gulp.emit (node:events:539:35)
at Gulp.emit (node:domain:475:12)
at Object.error (E:\docker\images\XXX\web\themes\custom\XXX\front\node_modules\undertaker\lib\helpers\createExtensions.js:61:10)
at handler (E:\docker\images\XXX\web\themes\custom\XXX\front\node_modules\now-and-later\lib\map.js:50:14)
at f (E:\docker\images\XXX\web\themes\custom\XXX\front\node_modules\once\once.js:25:25)
at f (E:\docker\images\XXX\web\themes\custom\XXX\front\node_modules\once\once.js:25:25)
at tryCatch (E:\docker\images\XXX\web\themes\custom\XXX\front\node_modules\async-done\index.js:24:15)
at done (E:\docker\images\XXX\web\themes\custom\XXX\front\node_modules\async-done\index.js:40:12)
My versions :
npm -v : 8.12.1
node -v : v16.15.1
gulp -v : CLI : 2.3.0 - Local : 4.0.2
How fix this error ?
Try to add global: true
transform: [babelify.configure({global: true, presets: ["#babel/preset-env"]})]
instead of replacing the theme.scss.liquid file with the compiled scss a _styles folder is created with the updated theme.scss.liquid
gulpfile.js
const requireDir = require('require-dir');
// Require all tasks in gulpfile.js/tasks, including subfolders
requireDir('./gulp/tasks', { recurse: true });
inside of tasks folder
watch.js
const config = require('../config');
const gulp = require('gulp');
const path = require('path');
const watch = require('gulp-watch');
gulp.task('watch', () => {
const task = config.tasks['styles'];
let filePattern;
if (task.filePattern) {
filePattern = task.filePattern;
} else {
filePattern = path.join(config.root.src, task.src, '**/*.{' + task.extensions.join(',') + '}');
}
watch(filePattern, gulp.parallel(task.watchTask));
});
styles.js
const config = require('../config');
const gulp = require('gulp');
const path = require('path');
const sass = require('gulp-sass');
const size = require('gulp-size');
const postcss = require('gulp-postcss');
const debug = require('gulp-debug');
const rename = require('gulp-rename');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const mergeStream = require('merge-stream');
const colors = require('ansi-colors');
const log = require('fancy-log');
const sassOptions = {
outputStyle: 'nested', // libsass doesn't support expanded yet
precision: 10,
errLogToConsole: true // else watch breaks
};
const postcssPlugins = [
autoprefixer(), // Browsers pulled from .browserslistrc
cssnano({
discardUnused: true, // don't discard unused at-rules (#keyframes for example that aren't used)
zindex: false, // don't optimize z-index stacking... very dangerous
autoprefixer: true // don't remove unnecessary prefixes. we're setting this above
})
];
const stylePipeline = (src) => {
const paths = {
src: path.join(config.root.src, config.tasks.styles.src, src),
dest: path.join(config.root.src, config.tasks.styles.dest)
};
return gulp.src(paths.src)
.pipe(sass(sassOptions))
.on('error', function(error) {
log.error(`${colors.bold.red('SCSS Compilation Error')}: ${error.message}`);
this.emit('end');
})
.pipe(postcss(postcssPlugins))
.pipe(rename({
extname: '.scss.liquid'
}))
.pipe(gulp.dest(paths.dest))
.pipe(debug())
.pipe(size({showFiles: true, title: 'CSS: size of'}));
}
// Run stylepipeline for each entry point file
gulp.task('styles', () => mergeStream.apply(gulp, config.tasks.styles.files.map(stylePipeline)));
notifications.js, scripts.js, start.js
config.js
module.exports = {
root: {
src: './'
},
tasks: {
styles: {
src: './_styles',
dest: './assets',
filePattern: ['./_styles/**/*.scss'],
files: ['theme.scss'],
watchTask: 'styles',
extensions: ['scss', 'css']
},
eslint: {
filePattern: ['./_scripts/**/*.js'],
extensions: ['js']
},
notifications: {
filePattern: ['./_notifications/**/*.scss'],
files: ['notifications.scss'],
src: './_notifications',
dest: './_notifications'
}
}
};
gulp folder for reference
information that might be useful
i'm running the project locally
maybe a working directory issue on my computer???
"devDependencies": {
"#babel/core": "^7.13.8",
"#babel/preset-env": "^7.13.9",
"ansi-colors": "^4.1.1",
"autoprefixer": "^10.2.4",
"babelify": "^10.0.0",
"browserify": "^17.0.0",
"cssnano": "^4.1.10",
"del": "^6.0.0",
"fancy-log": "^1.3.3",
"gulp": "^4.0.2",
"gulp-changed": "^1.3.2",
"gulp-concat": "^2.6.1",
"gulp-cssimport": "~3.0.2",
"gulp-debug": "^4.0.0",
"gulp-if": "^3.0.0",
"gulp-jshint": "^2.0.1",
"gulp-postcss": "^9.0.0",
"gulp-rename": "^2.0.0",
"gulp-sass": "^4.1.0",
"gulp-size": "^3.0.0",
"gulp-uglify": "^1.5.4",
"jshint": "^2.9.2",
"merge-stream": "^2.0.0",
"path": "^0.12.7",
"postcss": "^8.2.6",
"require-dir": "^1.2.0",
"run-sequence": "^2.2.1",
"swiper": "^6.5.0",
"uglifyify": "^5.0.2",
"vinyl-buffer": "^1.0.1",
"vinyl-source-stream": "^2.0.0",
"watchify": "^4.0.0",
"yargs": "^16.2.0",
"gulp-scss-lint": "^1.0.0"
},
"dependencies": {
"gulp-autoprefixer": "^7.0.1",
"gulp-babel": "^8.0.0",
"gulp-replace": "^1.1.3",
"gulp-scss-lint": "^1.0.0",
"gulp-watch": "^5.0.1",
"imagesloaded": "^4.1.4",
"jquery": "^3.6.0",
"navigo": "^8.9.0",
"throttle-debounce": "^3.0.1",
"youtube-player": "^5.5.2"
}
}
adding
.pipe(rename('theme.scss.liquid'))
to my styles.js file fixed everything
I'm trying to set up gulp to automatically refresh projects when I save changes via tutorials online.
It keeps throwing back errors every time I initiate "gulp serve"
Versions
node version - v12.13.0
npm version - 6.13.0
gulp version - 3.9.1
My gulpfile.js code:
var gulp = require('gulp');
var uglifycss = require('gulp-uglifycss');
var sass = require('gulp-sass');
var browserSync = require('browser-sync').create();
sass.compiler = require('node-sass');
gulp.task('sass', function () {
return gulp.src('./sass/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
gulp.task('sass:watch', function () {
gulp.watch('./sass/**/*.scss', ['sass']);
});
gulp.task('css', function () {
gulp.src('./styles/**/*.css')
.pipe(uglifycss({
"maxLineLen": 80,
"uglyComments": true
}))
.pipe(gulp.dest('./dist/'));
});
gulp.task('serve', ['sass'], function() {
browserSync.init({
server: "./app"
});
gulp.watch("app/scss/*.scss", ['sass']);
gulp.watch("app/*.html").on('change', browserSync.reload);
});
gulp.task('browser-sync', function() {
browserSync.init({
server: {
baseDir: "./"
}
});
});
gulp.task('js', function () {
return gulp.src('js/*js')
.pipe(browserify())
.pipe(uglify())
.pipe(gulp.dest('dist/js'));
});
gulp.task('js-watch', ['js'], function (done) {
browserSync.reload();
done();
});
gulp.task('default', ['js'], function () {
browserSync.init({
server: {
baseDir: "./"
}
});
gulp.watch("js/*.js", ['js-watch']);
});
My package.json code:
{
"name": "fifteen-projects",
"version": "1.0.0",
"description": "Project files",
"main": "gulpfile.js",
"dependencies": {
"gulp-uglifycss": "^1.1.0"
},
"devDependencies": {
"browser-sync": "^2.26.7",
"gulp": "^3.9.1",
"gulp-sass": "^4.0.2",
"node-sass": "^4.13.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/MarvinBrereton-creator/fifteen-projects.git"
},
"author": "Marvin Brereton",
"license": "MIT",
"bugs": {
"url": "https://github.com/MarvinBrereton-creator/fifteen-projects/issues"
},
"homepage": "https://github.com/MarvinBrereton-creator/fifteen-projects#readme"
}
When I initiate "gulp serve" in cmd inside the project folder where gulp is located it throws back:
fs.js:27const { Math, Object } = primordials;
ReferenceError: primordials is not defined
at fs.js:27:26
at req_ (C:\Users\kk\Documents\GitHub\fifteen-projects\node_modules\natives\index.js:143:24)
at Object.req [as require] (C:\Users\kk\Documents\GitHub\fifteen- projects\node_modules\natives\index.js:55:10)
at Object.<anonymous> (C:\Users\kk\Documents\GitHub\fifteen-projects\node_modules\vinyl- fs\node_modules\graceful-fs\fs.js:1:37)
at Module._compile (internal/modules/cjs/loader.js:956:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10)
at Module.load (internal/modules/cjs/loader.js:812:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:849:19)
at require (internal/modules/cjs/helpers.js:74:18)
I think the problems are coming from the Node_modules folder as the errors are coming from there whenever I try to initiate gulpfile.js
Any help is appreciated, thank you!
I found the best way was to use the inbuilt extension (Hot Reload) within VsCode. Gulp was outdated for what was needed.
I have a Less task in my Gulp script, but it's not working like it should:
1
It's supposed to compile less files and move them to 'build/css' folder. But for some reason it doesn't work. Why?
2
I tried to use gulp-util to log errors. It cathes wrong file name in imported less files. But it does not detect undefined classes. And it does not indicate why files are not compiled.
Any hints is much appreciated!
gulpfile.js
var gulp = require("gulp"),
util = require('gulp-util'),
minifyHTML = require("gulp-minify-html"),
concat = require("gulp-concat"),
uglify = require("gulp-uglify"),
cssmin = require("gulp-cssmin"),
uncss = require("gulp-uncss"),
imagemin = require("gulp-imagemin"),
sourcemaps = require("gulp-sourcemaps"),
inject = require("gulp-inject"),
less = require("gulp-less"),
filter = require("gulp-filter"),
glob = require("glob"),
browserSync = require("browser-sync"),
LessPluginAutoPrefix = require('less-plugin-autoprefix'),
autoprefix = new LessPluginAutoPrefix({
browsers: ["last 2 versions"]
});
var config = {
paths: {
html: {
src: "src/**/*.html",
dest: "build"
},
javascript: {
src: ["src/js/**/*.js"],
dest: "build/js"
},
css: {
src: ["src/css/**/*.css"],
dest: "build/css"
},
less: {
src: ["src/less/**/*.less", "!src/less/includes/**"],
dest: "build/css"
},
images: {
src: ["src/images/**/*.jpg", "src/images/**/*.jpeg", "src/images/**/*.png"],
dest: "build/images"
},
audio: {
src: "src/audio/**/*.mp3",
dest: "build/audio"
}
}
};
gulp.task("html", function(){
return gulp.src(config.paths.html.src)
.pipe(minifyHTML())
.pipe(gulp.dest(config.paths.html.dest));
});
gulp.task("scripts", function(){
return gulp.src(config.paths.javascript.src)
.pipe(sourcemaps.init())
.pipe(concat("app.min.js"))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest(config.paths.javascript.dest));
});
gulp.task("css", function(){
return gulp.src(config.paths.css.src)
.pipe(sourcemaps.init())
.pipe(cssmin())
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(config.paths.css.dest))
.pipe(browserSync.reload({stream: true}));
});
gulp.task("less", function(){
return gulp.src(config.paths.less.src)
.pipe(sourcemaps.init())
.pipe(less({
paths: ["node_modules/bootstrap/less"],
plugins: [autoprefix]
}))
.pipe(uncss({
html: glob.sync(config.paths.html.src)
}))
.pipe(concat("main.min.css"))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(config.paths.less.dest))
.pipe(filter("**/*.css"))
.pipe(browserSync.reload({stream: true}));
});
gulp.task("images", function(){
return gulp.src(config.paths.images.src)
.pipe(imagemin({
progressive: true,
interlaced: true
}))
.pipe(gulp.dest(config.paths.images.dest));
});
gulp.task("audio", function() {
return gulp.src([config.paths.audio.src]).pipe(gulp.dest(config.paths.audio.dest));
});
gulp.task("browser-sync", function() {
browserSync({
server: {
baseDir: "./build"
}
});
});
gulp.task("build", ["html", "scripts", "css", "less", "images", "audio"]);
gulp.task("default", ["build", "browser-sync"], function(){
gulp.watch(config.paths.html.src, ["html", browserSync.reload]);
gulp.watch(config.paths.javascript.src, ["scripts", browserSync.reload]);
gulp.watch(config.paths.css.src, ["css"]);
gulp.watch(config.paths.less.src, ["less"]);
gulp.watch(config.paths.images.src, ["images", browserSync.reload]);
gulp.watch(config.paths.audio.src, ["audio", browserSync.reload]);
});
package.json
{
"name": "ofj-simon-says",
"version": "0.1.0",
"description": "Click a color sequence",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"bower": "^1.3.12",
"browser-sync": "^2.14.0",
"glob": "^7.0.6",
"gulp": "^3.8.10",
"gulp-concat": "^2.4.1",
"gulp-cssmin": "^0.1.6",
"gulp-filter": "^4.0.0",
"gulp-imagemin": "^3.0.3",
"gulp-inject": "^4.1.0",
"gulp-less": "^3.1.0",
"gulp-minify-html": "^1.0.6",
"gulp-sourcemaps": "^1.2.8",
"gulp-uglify": "^2.0.0",
"gulp-uncss": "^1.0.6",
"gulp-util": "^3.0.7",
"less-plugin-autoprefix": "^1.5.1",
"main-bower-files": "^2.4.0"
},
"dependencies": {
"bootstrap": "^3.3.7"
}
}
Seems to be a problem with gulp-uncss plugin. When I remove it, everything works. I tried to update to newest version 1.0.6 but to no avail. I'll have to look more into it more deeply before saying what the problem is. For now I'm removing uncss() from the less task:
gulp.task("less", function(){
return gulp.src(config.paths.less.src)
.pipe(sourcemaps.init())
.pipe(less({
plugins: [autoprefix]
}).on('error', util.log))
.pipe(concat('main.min.css'))
//.pipe(uncss({
// html: glob.sync(config.paths.html.src)
//}))
.pipe(nano())
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(config.paths.less.dest))
.pipe(browserSync.reload({stream: true}));
});