Answer the question
In order to leave comments, you need to log in
Slick slider not working in dist folder, production, what am I doing wrong in gulpfile?
var gulp = require('gulp');
sass = require('gulp-sass'); //Include Scss package
browserSync = require('browser-sync'); // Connect Browser Sync
concat = require('gulp-concat'); // Include gulp-concat (for file concatenation)
uglify = require('gulp-uglifyjs'); // Include gulp-uglifyjs (for JS compression)
cssnano = require('gulp-cssnano'); // Include CSS minification package
rename = require('gulp-rename'); // Include the library for renaming files
del = require('del'); // Include the library for deleting files and folders
imagemin = require('gulp-imagemin');
pngquant = require('imagemin-pngquant'); // Include the library for working with png
cache = require('gulp-cache'); // Include the caching library
autoprefixer = require('gulp-autoprefixer');// Include the library to automatically add
cleanCSS = require('gulp-clean-css');
gulp.task('browser-sync', function() { // Create task browser-sync
browserSync({ // Execute browser Sync
server: { // Define server parameters
baseDir: 'app' // Server directory - app
} ,
notify: false // Disable notifications
});
});
gulp.task('sass', function(){ // Create a Sass task
return gulp.src('app/scss/**/*.scss') // Get the source
.pipe(sass()) // Convert Sass to CSS with gulp-sass
.pipe(autoprefixer(['last 15 versions' , '> 1%', 'ie 8', 'ie 7'], { cascade: true })) // Create Prefixes
.pipe(cssnano()) // Compress
.pipe(cleanCSS({compatibility: 'ie8' }))
.pipe(rename({suffix: '.min'})) // Add .min suffix
.pipe(gulp.dest('app/css')) // Dump result to app/css
folder .pipe( browserSync.reload({stream: true})) // Update the CSS on the page when it changes
});
gulp.task('scripts', function() {
return gulp.src([ // Get all required libraries
'app/libs/jquery/dist/jquery.min.js', // Get jQuery
'app/libs/slick/slick.min.js',
'app/js/common.js', // Always at the end
])
.pipe(concat('scripts.min.js')) // Bundle them up in a new file libs.min.js
.pipe(uglify()) // Compress the JS file
.pipe(gulp.dest(' app/js')); // Upload to the app/js folder
});
gulp.task('img', function() {
return gulp.src('app/img/**/*') // Grab all images from app
.pipe(cache(imagemin({ // Compress them with best settings based on caching
interlaced: true,
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use:
.pipe(gulp.dest('dist/img')); // Upload to production
});
gulp.task('watch', ['browser-sync', 'sass', 'scripts'], function() {
gulp.watch('app/scss/**/*.scss', ['sass'] ); // Watching sass files // Watching other types of files
gulp.watch('app/*.html', browserSync.reload); // Watching HTML files in the project root
gulp.watch('app/js/ **/*.js', browserSync.reload); // Watch for JS files in the js folder
});
gulp.task('default', ['watch']); // reset watch
gulp.task('clean', function() {
return del.sync('dist'); // Delete the dist folder before building
});
gulp.task('build', ['
var buildCss = gulp.src([ // Move libraries to production
'app/css/main.min.css'
])
.pipe(gulp.dest('dist/css'))
var buildFonts = gulp.src('app /fonts/**/*') // Move fonts to production
.pipe(gulp.dest('dist/fonts'))
var buildJs = gulp.src('app/js/scripts.min.js') // Porting scripts to production
.pipe(gulp.dest('dist/js'))
var buildHtml = gulp.src('app/*.html') // Porting HTML to production
.pipe(gulp.dest('dist') );s
});
gulp.task('clear', function () { // clearing the cache
return cache.clearAll();
})
and while I'm running the site using browserSync, everything works. As soon as I collect the build,
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