Last active
November 28, 2020 19:03
-
-
Save OlegShchavelev/d1da403d5b22dfa6790eb9bb09ef0ed5 to your computer and use it in GitHub Desktop.
Вопрос как получить Bootstap компоненты в папку scss/bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let gulp = require('gulp'); | |
let changed = require('gulp-changed'), | |
del = require('del'), | |
npmDist = require('gulp-npm-dist'), | |
sourcemaps = require('gulp-sourcemaps'), | |
sass = require('gulp-sass'), | |
autoprefixer = require('gulp-autoprefixer'), | |
rename = require('gulp-rename'), | |
cleanCSS = require('gulp-clean-css'), | |
path = require('path'); | |
let srcMarkupFiles = 'pages/*.html' | |
let srcSassFiles = 'scss/style.default.scss' | |
let distMainDir = 'dist/' | |
let distPageDir = 'dist/' | |
let distStyleDir = 'dist/css/' | |
let distVendorDir = 'dist/vendor/' | |
let copy = ['js/**', 'img/**', 'fonts/**', 'css/photoswipe/*', 'css/custom.css', 'favicon.png', 'icons/**', 'docs/**'] | |
var config = { | |
autoprefixer: { | |
cascade: false | |
}, | |
sass: { | |
outputStyle: 'expanded', | |
includePaths: ['src/scss'] | |
} | |
} | |
// Clean the dist folder - for clean builds | |
gulp.task('clean', function () { | |
return del([ | |
distMainDir + '**/*' | |
]); | |
}); | |
// Copy changed HTML | |
gulp.task('html', function () { | |
return gulp.src(srcMarkupFiles) | |
// only pass changed files | |
.pipe(changed(distMainDir)) | |
//save all the files | |
.pipe(gulp.dest(distMainDir)); | |
}); | |
// Dev SASS Task - no sourcemaps, no autoprefixing, no minification | |
gulp.task('sass-dev', function () { | |
return gulp.src(srcSassFiles) | |
.pipe(sass(config.sass).on('error', sass.logError)) | |
.pipe(autoprefixer(config.autoprefixer)) | |
.pipe(gulp.dest(distStyleDir)); | |
}); | |
// Build SASS Task - sourcemaps, minification | |
gulp.task('sass-build', function () { | |
return gulp.src(srcSassFiles) | |
.pipe(sourcemaps.init()) | |
.pipe(sass(config.sass).on('error', sass.logError)) | |
.pipe(autoprefixer(config.autoprefixer)) | |
.pipe(gulp.dest(distStyleDir)) | |
.pipe(cleanCSS()) | |
.pipe(rename({ | |
suffix: '.min' | |
})) | |
.pipe(sourcemaps.write('.')) | |
.pipe(gulp.dest(distStyleDir)); | |
}); | |
// Copy folders defined in copy array | |
gulp.task('copy', function () { | |
return getFoldersSrc('pages', copy) | |
.pipe(changed(distMainDir)) | |
.pipe(gulp.dest(distPageDir)); | |
}); | |
// Copy 3rd party modules to the vendor directory based on our package.json dependencies | |
// If running in dev mode w/ Browser Sync, there is no watcher set for this, it executes | |
// only when calling initial `gulp` command or you run `gulp vendor` separately | |
gulp.task('vendor', function () { | |
return gulp.src(npmDist({ | |
copyUnminified: true | |
}), { | |
base: './node_modules/' | |
}) | |
.pipe(rename(function (path) { | |
path.dirname = path.dirname.replace(/\/distribute/, '').replace(/\\distribute/, '').replace(/\/dist/, '').replace(/\\dist/, ''); | |
})) | |
.pipe(gulp.dest(distVendorDir)); | |
}); | |
// Build Gulp Task | |
// 1. Clean dist folder | |
// 2. Process HTML, vendor dir, SCSS w/ source maps and minification and copy static assets | |
gulp.task('build', | |
gulp.series( | |
'clean', | |
gulp.parallel('vendor', 'html', 'sass-build', 'copy'))); | |
function getFolders(base, folders) { | |
return folders.map(function (item) { | |
return path.join(base, item); | |
}); | |
}; | |
function getFoldersSrc(base, folders) { | |
return gulp.src(folders.map(function (item) { | |
return path.join(base, item); | |
}), { | |
base: base, | |
allowEmpty: true | |
}); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment