This commit is contained in:
0dp 2018-05-02 12:27:12 +02:00
parent b6867bf6f6
commit 4b01b22fb4
2 changed files with 39 additions and 14 deletions

View File

@ -20,6 +20,7 @@ var cleanCSS = require( 'gulp-clean-css' );
var gulpSequence = require( 'gulp-sequence' );
var replace = require( 'gulp-replace' );
var autoprefixer = require( 'gulp-autoprefixer' );
var rev = require('gulp-rev');
// Configuration file to keep your code DRY
var cfg = require( './gulpconfig.json' );
@ -94,6 +95,16 @@ gulp.task( 'cssnano', function() {
.pipe( gulp.dest( paths.css ) );
});
gulp.task( 'rev', function() {
// by default, gulp would pick `assets/css` as the base,
// so we need to set it explicitly:
gulp.src([paths.css + '/theme.min.css', paths.js + '/theme.min.js'], {base: './'})
.pipe(rev())
.pipe(gulp.dest('./')) // write rev'd assets to build dir
.pipe(rev.manifest())
.pipe(gulp.dest('./')); // write manifest to build dir
});
gulp.task( 'minifycss', function() {
return gulp.src( paths.css + '/theme.css' )
.pipe( sourcemaps.init( { loadMaps: true } ) )
@ -116,7 +127,7 @@ gulp.task( 'cleancss', function() {
});
gulp.task( 'styles', function( callback ) {
gulpSequence( 'sass', 'minifycss' )( callback );
gulpSequence( 'sass', 'minifycss', 'rev' )( callback );
} );
// Run:
@ -157,6 +168,8 @@ gulp.task( 'scripts', function() {
gulp.src( scripts )
.pipe( concat( 'theme.js' ) )
.pipe( gulp.dest( paths.js ) );
rev();
});
// Deleting any file inside the /src folder

View File

@ -5,23 +5,35 @@
* @package understrap
*/
/**
* @param string $filename
* @return string
*/
function asset_path($filename) {
$manifest_path = get_stylesheet_directory_uri() .'/rev-manifest.json';
if (isset($manifest_path)) {
$manifest = json_decode(file_get_contents($manifest_path), TRUE);
} else {
$manifest = [];
}
if (array_key_exists($filename, $manifest)) {
return $manifest[$filename];
}
return $filename;
}
if ( ! function_exists( 'understrap_scripts' ) ) {
/**
* Load theme's JavaScript and CSS sources.
*/
function understrap_scripts() {
// Get the theme data.
$the_theme = wp_get_theme();
$theme_version = $the_theme->get( 'Version' );
$css_version = $theme_version . '.' . filemtime(get_template_directory() . '/css/theme.min.css');
wp_enqueue_style( 'understrap-styles', get_stylesheet_directory_uri() . '/css/theme.min.css', array(), $css_version );
wp_enqueue_style( 'understrap-styles', get_stylesheet_directory_uri() . '/'. asset_path('css/child-theme.min.css'), array(), null);
wp_enqueue_script( 'jquery');
wp_enqueue_script( 'popper-scripts', get_template_directory_uri() . '/js/popper.min.js', array(), $theme_version, true);
wp_enqueue_script( 'popper-scripts', get_template_directory_uri() . '/js/popper.min.js', array(), false, true);
$js_version = $theme_version . '.' . filemtime(get_template_directory() . '/js/theme.min.js');
wp_enqueue_script( 'understrap-scripts', get_template_directory_uri() . '/js/theme.min.js', array(), $js_version, true );
wp_enqueue_script( 'understrap-scripts', get_template_directory_uri() . '/' . asset_path('js/child-theme.min.js'), array(), null, true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}