Created
August 14, 2023 17:34
-
-
Save antmbraun/436e578011aca3d22529647625a2684f to your computer and use it in GitHub Desktop.
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
// Load plugins | |
var | |
autoprefixer = require("autoprefixer"), // CSS vendor prefixes | |
cssnano = require("cssnano"), // Minify CSS | |
postcss = require("gulp-postcss"), // PostCSS | |
concat = require("gulp-concat"), // Combine files | |
gulp = require("gulp"), | |
gulpSass = require('gulp-sass')(require('sass')), // Compile Sass | |
inlineImage = require("gulp-inline-image"), // Allow for base64 icons via inline-image() | |
rename = require("gulp-rename"), // Rename files | |
size = require('gulp-size'), | |
terser = require("gulp-terser"); // Minify JS | |
// Commonly used paths | |
var paths = { | |
output: "dist/", | |
js: { | |
input: [ // Items are in load order. | |
"js/initialLoad/**/**/*.js", | |
"js/main/**/*.js", | |
"dist/patterns/_patterns/**/*.js", | |
] | |
}, | |
stylesMain: { | |
watch: "scss/**", | |
input: "scss/main.scss", | |
output: "dist/" | |
}, | |
}; | |
/** | |
* buildCSS | |
* Process and minify SCSS files | |
* Gulp command: gulp buildCSS | |
*/ | |
function buildCSS() { | |
// mainStream contains all CSS | |
var mainStream = gulp.src(paths.stylesMain.input) | |
.pipe(gulpSass().on("error", gulpSass.logError)) // Compile Sass into CSS | |
.pipe(inlineImage()) // Convert SVGs using inline-image() into Base64 | |
.pipe(postcss([autoprefixer(), cssnano()])) | |
.pipe(concat("main.css")) | |
.pipe(rename({ suffix: ".min" })) | |
.pipe(size({ showFiles: true })) // Print the size of the minified CSS file | |
.pipe(gulp.dest(paths.output)); // This file is included in mindbody.libraries.yml | |
return mainStream; | |
}; | |
/** | |
* buildJS() | |
* Build main script | |
* Gulp command: gulp buildJS | |
*/ | |
function buildJS() { | |
return gulp.src(paths.js.input) // Pull in the various paths. | |
.pipe(terser()).on("error", console.error) | |
.pipe(concat("main.js")) | |
.pipe(gulp.dest("dist/")) // This file is included in mindbody.libraries.yml | |
}; | |
/** | |
* watch() | |
* Gulp command: gulp watch | |
*/ | |
function watch() { | |
// Run CSS tasks when changes are detected | |
gulp.watch( | |
[ | |
paths.stylesMain.watch, | |
], | |
buildCSS); | |
// Run JS tasks when changes are detected | |
gulp.watch( | |
[ | |
...paths.js.input, | |
], | |
buildJS); | |
}; | |
/** | |
* Exports | |
* Exports to expose functions | |
* Can be used to run them individually | |
*/ | |
exports.buildCSS = buildCSS; | |
exports.buildJS = buildJS; | |
exports.watch = watch; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment