-
-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
📦 NEW: Compile multiple CSS files into different directories #125
base: master
Are you sure you want to change the base?
Changes from 4 commits
b3407c3
63627a6
670cd0f
b2cd627
1091db0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,9 @@ const cache = require( 'gulp-cache' ); // Cache files in stream for later use. | |
const remember = require( 'gulp-remember' ); // Adds all the files it has ever seen back into the stream. | ||
const plumber = require( 'gulp-plumber' ); // Prevent pipe breaking caused by errors from gulp plugins. | ||
const beep = require( 'beepbeep' ); | ||
const merge = require( 'merge-stream' ); | ||
const gulpif = require('gulp-if'); | ||
const defaults = require('lodash.defaults'); | ||
|
||
/** | ||
* Custom Error Handler. | ||
|
@@ -99,22 +102,22 @@ const reload = done => { | |
}; | ||
|
||
/** | ||
* Task: `styles`. | ||
* | ||
* Compiles Sass, Autoprefixes it and Minifies CSS. | ||
* | ||
* This task does the following: | ||
* 1. Gets the source scss file | ||
* 2. Compiles Sass to CSS | ||
* 3. Writes Sourcemaps for it | ||
* 4. Autoprefixes it and generates style.css | ||
* This function does the following: | ||
* 1. Compiles Sass to CSS | ||
* 2. Writes Sourcemaps for it | ||
* 3. Autoprefixes it and generates .css | ||
* 4. Renames the CSS file with suffix -rtl and generates -rtl.css | ||
* 5. Renames the CSS file with suffix .min.css | ||
* 6. Minifies the CSS file and generates style.min.css | ||
* 6. Minifies the CSS file and generates .min.css | ||
* 7. Injects CSS or reloads the browser via browserSync | ||
*/ | ||
gulp.task( 'styles', () => { | ||
return gulp | ||
.src( config.styleSRC, { allowEmpty: true }) | ||
function processStyle( gulpStream, processOptions = {} ) { | ||
processOptions = defaults( processOptions, { | ||
isRTL: false, | ||
styleDestination: './', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even with simple styles the |
||
} ); | ||
|
||
return gulpStream | ||
.pipe( plumber( errorHandler ) ) | ||
.pipe( sourcemaps.init() ) | ||
.pipe( | ||
|
@@ -128,19 +131,75 @@ gulp.task( 'styles', () => { | |
.pipe( sourcemaps.write({ includeContent: false }) ) | ||
.pipe( sourcemaps.init({ loadMaps: true }) ) | ||
.pipe( autoprefixer( config.BROWSERS_LIST ) ) | ||
.pipe( sourcemaps.write( './' ) ) | ||
.pipe( gulpif( ! processOptions.isRTL, sourcemaps.write( './' ) ) ) // Write source map at this step if not RTL. | ||
.pipe( lineec() ) // Consistent Line Endings for non UNIX systems. | ||
.pipe( gulp.dest( config.styleDestination ) ) | ||
mintbird marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.pipe( gulpif( processOptions.isRTL, rename({ suffix: '-rtl' }) ) ) // Append "-rtl" to the filename. | ||
.pipe( gulpif( processOptions.isRTL, rtlcss() ) ) // Convert to RTL. | ||
.pipe( gulpif( processOptions.isRTL, sourcemaps.write( './' ) ) ) // Write source map at this step if RTL. | ||
.pipe( gulp.dest( processOptions.styleDestination ) ) | ||
.pipe( filter( '**/*.css' ) ) // Filtering stream to only css files. | ||
.pipe( mmq({ log: true }) ) // Merge Media Queries only for .min.css version. | ||
.pipe( browserSync.stream() ) // Reloads style.css if that is enqueued. | ||
.pipe( rename({ suffix: '.min' }) ) | ||
.pipe( minifycss({ maxLineLen: 10 }) ) | ||
.pipe( lineec() ) // Consistent Line Endings for non UNIX systems. | ||
.pipe( gulp.dest( config.styleDestination ) ) | ||
.pipe( gulp.dest( processOptions.styleDestination ) ) | ||
.pipe( filter( '**/*.css' ) ) // Filtering stream to only css files. | ||
.pipe( browserSync.stream() ) // Reloads style.min.css if that is enqueued. | ||
.pipe( notify({ message: '\n\n✅ ===> STYLES — completed!\n', onLast: true }) ); | ||
; | ||
} | ||
|
||
/** | ||
* Task: `styles`. | ||
* | ||
* Compiles Sass, Autoprefixes it and Minifies CSS. | ||
* | ||
* This task does the following: | ||
* 1. Gets the source scss file | ||
* 2. Compiles Sass to CSS | ||
* 3. Writes Sourcemaps for it | ||
* 4. Autoprefixes it and generates style.css | ||
* 5. Renames the CSS file with suffix .min.css | ||
* 6. Minifies the CSS file and generates style.min.css | ||
* 7. Injects CSS or reloads the browser via browserSync | ||
*/ | ||
gulp.task( 'styles', () => { | ||
return processStyle( | ||
gulp.src( config.styleSRC, { allowEmpty: true }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing |
||
).pipe( notify({ message: '\n\n✅ ===> STYLES — completed!\n', onLast: true }) ); | ||
}); | ||
|
||
/** | ||
* Task: `addonStyles`. | ||
* | ||
* Compiles Sass, Autoprefixes it and Minifies CSS. | ||
* | ||
* This task does the following: | ||
* 1. Gets the source scss file | ||
* 2. Compiles Sass to CSS | ||
* 3. Writes Sourcemaps for it | ||
* 4. Autoprefixes it and generates CSS file | ||
* 5. Renames the CSS file with suffix .min.css | ||
* 6. Minifies the CSS file and generates .min.css | ||
* 7. Injects CSS or reloads the browser via browserSync | ||
*/ | ||
gulp.task( 'addonStyles', ( done ) => { | ||
// Exit task when no addon styles | ||
if ( config.addonStyles.length === 0 ) { | ||
return done(); | ||
} | ||
|
||
// Process each addon style | ||
var tasks = config.addonStyles.map( function ( addon ) { | ||
|
||
return processStyle( | ||
gulp.src( addon.styleSRC, { allowEmpty: true }), | ||
{ styleDestination: addon.styleDestination } | ||
).pipe( notify({ message: '\n\n✅ ===> ADDON STYLES — completed!\n', onLast: true }) ); | ||
|
||
} ); | ||
|
||
return merge( tasks ); | ||
}); | ||
|
||
/** | ||
|
@@ -159,36 +218,48 @@ gulp.task( 'styles', () => { | |
* 9. Injects CSS or reloads the browser via browserSync | ||
*/ | ||
gulp.task( 'stylesRTL', () => { | ||
return gulp | ||
.src( config.styleSRC, { allowEmpty: true }) | ||
.pipe( plumber( errorHandler ) ) | ||
.pipe( sourcemaps.init() ) | ||
.pipe( | ||
sass({ | ||
errLogToConsole: config.errLogToConsole, | ||
outputStyle: config.outputStyle, | ||
precision: config.precision | ||
}) | ||
) | ||
.on( 'error', sass.logError ) | ||
.pipe( sourcemaps.write({ includeContent: false }) ) | ||
.pipe( sourcemaps.init({ loadMaps: true }) ) | ||
.pipe( autoprefixer( config.BROWSERS_LIST ) ) | ||
.pipe( lineec() ) // Consistent Line Endings for non UNIX systems. | ||
.pipe( rename({ suffix: '-rtl' }) ) // Append "-rtl" to the filename. | ||
.pipe( rtlcss() ) // Convert to RTL. | ||
.pipe( sourcemaps.write( './' ) ) // Output sourcemap for style-rtl.css. | ||
.pipe( gulp.dest( config.styleDestination ) ) | ||
.pipe( filter( '**/*.css' ) ) // Filtering stream to only css files. | ||
.pipe( browserSync.stream() ) // Reloads style.css or style-rtl.css, if that is enqueued. | ||
.pipe( mmq({ log: true }) ) // Merge Media Queries only for .min.css version. | ||
.pipe( rename({ suffix: '.min' }) ) | ||
.pipe( minifycss({ maxLineLen: 10 }) ) | ||
.pipe( lineec() ) // Consistent Line Endings for non UNIX systems. | ||
.pipe( gulp.dest( config.styleDestination ) ) | ||
.pipe( filter( '**/*.css' ) ) // Filtering stream to only css files. | ||
.pipe( browserSync.stream() ) // Reloads style.css or style-rtl.css, if that is enqueued. | ||
.pipe( notify({ message: '\n\n✅ ===> STYLES RTL — completed!\n', onLast: true }) ); | ||
return processStyle( | ||
gulp.src( config.styleSRC, { allowEmpty: true }), | ||
mintbird marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ isRTL: true } | ||
).pipe( notify({ message: '\n\n✅ ===> STYLES RTL — completed!\n', onLast: true }) ); | ||
|
||
}); | ||
|
||
/** | ||
* Task: `addonStylesRTL`. | ||
* | ||
* Compiles Sass, Autoprefixes it, Generates RTL stylesheet, and Minifies CSS. | ||
* | ||
* This task does the following: | ||
* 1. Gets the source scss file | ||
* 2. Compiles Sass to CSS | ||
* 4. Autoprefixes it and generates style.css | ||
* 5. Renames the CSS file with suffix -rtl and generates -rtl.css | ||
* 6. Writes Sourcemaps for -rtl.css | ||
* 7. Renames the CSS files with suffix .min.css | ||
* 8. Minifies the CSS file and generates -rtl.min.css | ||
* 9. Injects CSS or reloads the browser via browserSync | ||
*/ | ||
gulp.task( 'addonStylesRTL', ( done ) => { | ||
// Exit task when no addon styles | ||
if ( config.addonStyles.length === 0 ) { | ||
return done(); | ||
} | ||
|
||
// Process each addon style | ||
var tasks = config.addonStyles.map( function ( addon ) { | ||
|
||
return processStyle( | ||
gulp.src( addon.styleSRC, { allowEmpty: true }), | ||
{ | ||
styleDestination: addon.styleDestination, | ||
isRTL: true, | ||
} | ||
).pipe( notify({ message: '\n\n✅ ===> ADDON STYLES RTL — completed!\n', onLast: true }) ); | ||
|
||
} ); | ||
|
||
return merge( tasks ); | ||
}); | ||
|
||
/** | ||
|
@@ -357,7 +428,7 @@ gulp.task( | |
'default', | ||
gulp.parallel( 'styles', 'vendorsJS', 'customJS', 'images', browsersync, () => { | ||
gulp.watch( config.watchPhp, reload ); // Reload on PHP file changes. | ||
gulp.watch( config.watchStyles, gulp.parallel( 'styles' ) ); // Reload on SCSS file changes. | ||
gulp.watch( config.watchStyles, gulp.parallel( 'styles', 'addonStyles' ) ); // Reload on SCSS file changes. | ||
gulp.watch( config.watchJsVendor, gulp.series( 'vendorsJS', reload ) ); // Reload on vendorsJS file changes. | ||
gulp.watch( config.watchJsCustom, gulp.series( 'customJS', reload ) ); // Reload on customJS file changes. | ||
gulp.watch( config.imgSRC, gulp.series( 'images', reload ) ); // Reload on customJS file changes. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the right place for content like this. Kindly, create a new heading after installation call it, FAQs, ask a question and then answer it. 👍