Gulp task refactored for in-place CSS minification
This commit is contained in:
parent
acb896e2f3
commit
15f02cbe83
45
Gulpfile.js
45
Gulpfile.js
@ -1,12 +1,17 @@
|
|||||||
var gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
var clean = require('gulp-clean');
|
const clean = require('gulp-clean');
|
||||||
var copy = require('gulp-copy');
|
const copy = require('gulp-copy');
|
||||||
var zip = require('gulp-zip');
|
const zip = require('gulp-zip');
|
||||||
var composer = require('gulp-composer');
|
const composer = require('gulp-composer');
|
||||||
var phpunit = require('gulp-phpunit');
|
const phpunit = require('gulp-phpunit');
|
||||||
var exec = require('child_process').exec;
|
const exec = require('child_process').exec;
|
||||||
var phpcs = require('gulp-phpcs');
|
const phpcs = require('gulp-phpcs');
|
||||||
var config = require('./package.json');
|
const cleanCSS = require('gulp-clean-css');
|
||||||
|
const argv = require('yargs').argv;
|
||||||
|
|
||||||
|
const config = require('./package.json');
|
||||||
|
const dev = argv.dev;
|
||||||
|
const finalName = config.name + '.' + config.version;
|
||||||
|
|
||||||
// Clean the target directory.
|
// Clean the target directory.
|
||||||
gulp.task('clean', function () {
|
gulp.task('clean', function () {
|
||||||
@ -43,19 +48,33 @@ gulp.task('test-cs', function (cb) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Bundle files as required for plugin distribution..
|
|
||||||
|
// Bundle files as required for plugin distribution.
|
||||||
gulp.task('bundle', ['clean'], function () {
|
gulp.task('bundle', ['clean'], function () {
|
||||||
console.log('Collecting files for package dist/' + config.name + config.version + ' ...');
|
console.log('Collecting files for package dist/' + config.name + config.version + ' ...');
|
||||||
return gulp.src(['**/*.php', 'styles/*.css', '!test/**', '!vendor/**', 'README.md', 'LICENSE.md'], {base: './'})
|
return gulp.src(['**/*.php', 'styles/*.css', '!test/**', '!vendor/**', 'README.md', 'LICENSE.md'], {base: './'})
|
||||||
.pipe(copy('./dist/' + config.name + '.' + config.version + '/' + config.name));
|
.pipe(copy('./dist/' + finalName + '/' + config.name));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Minify CSS.
|
||||||
|
gulp.task('minify-css', function () {
|
||||||
|
if (!dev) {
|
||||||
|
console.log('Minifying CSS ...');
|
||||||
|
return gulp.src('./dist/' + finalName + '/' + config.name + '/styles/*.css')
|
||||||
|
.pipe(cleanCSS({compatibility: 'ie9'}))
|
||||||
|
.pipe(gulp.dest('./dist/' + finalName + '/' + config.name + '/styles/'));
|
||||||
|
} else {
|
||||||
|
console.log('Development flag detected, not minifying CSS ...');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create a ZIP package of the relevant files for plugin distribution.
|
// Create a ZIP package of the relevant files for plugin distribution.
|
||||||
gulp.task('package', ['bundle'], function () {
|
gulp.task('package', ['bundle'], function () {
|
||||||
console.log('Building package dist/' + config.name + config.version + '.zip ...');
|
console.log('Building package dist/' + config.name + config.version + '.zip ...');
|
||||||
return gulp.src('./dist/' + config.name + '.' + config.version + '/**')
|
return gulp.src('./dist/' + config.name + '.' + config.version + '/**')
|
||||||
.pipe(zip(config.name + '.' + config.version + '.zip'))
|
.pipe(zip(finalName + '.zip'))
|
||||||
.pipe(gulp.dest('./dist'));
|
.pipe(gulp.dest('./dist'));
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('default', ['clean', 'compose', 'test', 'test-cs', 'bundle', 'package']);
|
gulp.task('default', ['clean', 'compose', 'test', 'test-cs', 'bundle', 'minify-css', 'package']);
|
||||||
|
@ -203,7 +203,7 @@ class WPLiveticker2 {
|
|||||||
public static function enqueue_styles() {
|
public static function enqueue_styles() {
|
||||||
// Only add if shortcode is present.
|
// Only add if shortcode is present.
|
||||||
if ( self::$shortcode_present ) {
|
if ( self::$shortcode_present ) {
|
||||||
wp_enqueue_style( 'wplt-css', WPLT2_BASE . 'styles/wp-liveticker2.min.css', '', self::VERSION, 'all' );
|
wp_enqueue_style( 'wplt-css', WPLT2_BASE . 'styles/wp-liveticker2.css', '', self::VERSION, 'all' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,6 @@ function wplt_enqueue_scripts() {
|
|||||||
global $post;
|
global $post;
|
||||||
// Register frontend CSS
|
// Register frontend CSS
|
||||||
if ( has_shortcode( $post->post_content, 'liveticker') )
|
if ( has_shortcode( $post->post_content, 'liveticker') )
|
||||||
wp_enqueue_style( 'wplt-css', WPLT_PLUGIN_URL . 'includes/css/wp-liveticker2.min.css', '', WPLT_VERSION, 'all' );
|
wp_enqueue_style( 'wplt-css', WPLT_PLUGIN_URL . 'includes/css/wp-liveticker2.css', '', WPLT_VERSION, 'all' );
|
||||||
}
|
}
|
||||||
add_action( 'wp_enqueue_scripts', 'wplt_enqueue_scripts' );
|
add_action( 'wp_enqueue_scripts', 'wplt_enqueue_scripts' );
|
@ -13,6 +13,7 @@
|
|||||||
"gulp-phpunit": "^0.24.1",
|
"gulp-phpunit": "^0.24.1",
|
||||||
"gulp-phpcs": "^2.1.0",
|
"gulp-phpcs": "^2.1.0",
|
||||||
"gulp-clean-css": "^3.9.0",
|
"gulp-clean-css": "^3.9.0",
|
||||||
"child_process": "^1.0.2"
|
"child_process": "^1.0.2",
|
||||||
|
"yargs": "^10.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1
styles/wp-liveticker2.min.css
vendored
1
styles/wp-liveticker2.min.css
vendored
@ -1 +0,0 @@
|
|||||||
ul.wplt2_ticker{list-style-type:none}li.wplt2_tick{background-color:#f5f5f5;margin:.1em;padding:.1em .3em}li.wplt2_tick p{margin:.3em}span.wplt2_tick_time{color:#002c58;font-size:.7em;font-style:italic}span.wplt2_tick_title{color:#002c58;font-weight:700;margin-left:.5em}p.wplt2_tick_content{margin-top:-.7em;text-indent:.5em}ul.wplt_2widget{list-style-type:none;margin-top:-.5em}ul.wplt2_widget li{text-align:left}span.wplt2_widget_time{font-size:.7em;font-style:italic}span.wplt2_widget_content{color:#002c58;text-indent:.2em}span.wplt2_widget_content_new{color:maroon;text-indent:.2em}p.wplt2_widget_link{text-align:right}
|
|
Loading…
x
Reference in New Issue
Block a user