Skip to content

Commit a25f205

Browse files
committed
changes to the gulp setup and a general refresh
1 parent af4a661 commit a25f205

File tree

21 files changed

+4499
-7895
lines changed

21 files changed

+4499
-7895
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Gulp + WordPress
22

3-
Version: 2.0.9
3+
Version: 2.1.0
44

55
## Author
66

@@ -16,15 +16,15 @@ The theme has been built according to [WordPress Coding Standards](https://make.
1616

1717
*Gulp + WordPress* is packaged with Gulp v4 for watching, compiling, and minifying SCSS and JS files.
1818

19-
A selection of helpful mixins is also included, most of which are featured in [this useful article](http://zerosixthree.se/8-sass-mixins-you-must-have-in-your-toolbox/) by [@seb_ekstrom](https://twitter.com/seb_ekstrom).
19+
Any SCSS files that are made alongside `core.scss` will be turned into individual CSS files, which could, for example, then be used for Gutenberg blocks.
2020

2121
You may also write your JavaScript in ES6 – The Gulp scripts task utilises [Babel](https://babeljs.io/), so you can use new syntax without worrying about browser support.
2222

2323
## Installation
2424

2525
Clone the project into `wp-content/themes` and rename it accordingly.
2626

27-
You’ll want to update `style.css` in the theme root with all the relevant bits of information, as well as `assets/package.json` (specifically `name` and `author`) and lastly `assets/gulpfile.js` (change the `themePrefix` variable accordingly).
27+
You’ll want to update `style.css` in the theme root with all the relevant bits of information, as well as `assets/package.json` (specifically `name` and `author`).
2828

2929
Now, in Terminal, `cd` into the `assets` directory and install the Gulp packages (if you haven't already installed Gulp, you’ll need to [do so](https://github.com/gulpjs/gulp/blob/master/docs/getting-started.md) first):
3030

@@ -34,9 +34,9 @@ Once you have installed the packages, in Terminal and while still in the `assets
3434

3535
SCSS files in `assets/scss/` are compiled and minified over to `assets/css`.
3636

37-
JavaScript files in `assets/js/scripts/` are uglified, concatenated and sent over to `assets/js/`.
38-
39-
> Note: If you would like to specify scripts per WordPress template (e.g. posts, pages etc.), you can tweak the `js` Gulp task to create separate JavaScript files.
37+
JavaScript files in `assets/js/src` are packaged over to `assets/js/dist`.
38+
It’s possible to add JS files to the `srcJsCoreFiles` var in `gulpfile.js`. These files will then be included in the packaged `core.min.js` file.
39+
You can also add JS files in `assets/js/src/components`, however these will not be concatenated and will instead be minified into individual JS files – this is useful if you need to split out your JS for Gutenberg blocks, or, say, have JS load on a particular archive template.
4040

4141
## Features
4242

File renamed without changes.

assets/gulpfile.js

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,28 @@ const concat = require('gulp-concat');
99
const rename = require('gulp-rename');
1010
const uglify = require('gulp-uglify');
1111
const scsslint = require('gulp-scss-lint');
12-
13-
/**
14-
* Here we set a prefix for our compiled and stylesheet and scripts.
15-
* Note that this should be the same as the `$themeHandlePrefix` in `func-script.php` and `func-style.php`.
16-
*/
17-
const themePrefix = 'theme-name';
12+
const clean = require('gulp-clean');
1813

1914
/**
2015
* Paths and files
2116
*/
2217
const srcScss = 'scss/**/*.scss';
2318
const srcJsDir = 'js';
24-
const srcJsFiles = [
25-
`${srcJsDir}/scripts/common.js`,
19+
const srcJsCoreFiles = [
20+
// `./node_modules/bootstrap/dist/js/bootstrap.js`,
21+
`${srcJsDir}/src/core.js`,
22+
];
23+
const srcJsComponentFiles = [
24+
`${srcJsDir}/src/components/*.js`,
2625
];
2726
const destCss = 'css';
28-
const destJs = 'js';
27+
const destJs = 'js/dist';
28+
const srcClean = [
29+
`${destCss}/*.min.css`,
30+
`!${destCss}/.gitkeep`,
31+
`${destJs}/*.min.js`,
32+
`!${destJs}/.gitkeep`
33+
]
2934

3035
/**
3136
* Scss lint
@@ -35,6 +40,14 @@ gulp.task('scss-lint', () => {
3540
.pipe(scsslint());
3641
});
3742

43+
/**
44+
* Clean directories containing minified assets
45+
*/
46+
gulp.task('clean-dirs', () => {
47+
return gulp.src(srcClean, {read: false})
48+
.pipe(clean())
49+
});
50+
3851
/**
3952
* Task for styles.
4053
*
@@ -44,22 +57,36 @@ gulp.task('css', gulp.series('scss-lint', () => {
4457
return gulp.src(srcScss)
4558
.pipe(sass().on('error', sass.logError))
4659
.pipe(autoprefixer({ cascade : false }))
47-
.pipe(rename(`${themePrefix}.min.css`))
60+
.pipe(rename({
61+
suffix: `.min`
62+
}))
4863
.pipe(cleancss())
4964
.pipe(gulp.dest(destCss));
5065
}));
5166

5267
/**
5368
* Task for scripts.
5469
*
55-
* Js files are uglified and sent over to `assets/js/scripts/`.
70+
* Js files are uglified and sent over to `assets/js/dist/`.
5671
*/
57-
gulp.task('js', () => {
58-
return gulp.src(srcJsFiles)
72+
gulp.task('js-core', () => {
73+
return gulp.src(srcJsCoreFiles)
5974
.pipe(babel({
6075
presets : ['@babel/env']
6176
}))
62-
.pipe(concat(`${themePrefix}.min.js`))
77+
.pipe(concat(`core.min.js`))
78+
.pipe(uglify())
79+
.pipe(gulp.dest(destJs));
80+
});
81+
82+
gulp.task('js-components', () => {
83+
return gulp.src(srcJsComponentFiles)
84+
.pipe(babel({
85+
presets : ['@babel/env']
86+
}))
87+
.pipe(rename({
88+
suffix: `.min`
89+
}))
6390
.pipe(uglify())
6491
.pipe(gulp.dest(destJs));
6592
});
@@ -69,10 +96,11 @@ gulp.task('js', () => {
6996
*/
7097
gulp.task('watch', () => {
7198
gulp.watch(srcScss, gulp.series('css'));
72-
gulp.watch(srcJsFiles, gulp.series('js'));
99+
gulp.watch(srcJsCoreFiles, gulp.series('js-core'));
100+
gulp.watch(srcJsComponentFiles, gulp.series('js-components'));
73101
});
74102

75103
/**
76104
* Default task
77105
*/
78-
gulp.task('default', gulp.series('css', 'js') );
106+
gulp.task('default', gulp.series('clean-dirs', 'css', 'js-core', 'js-components') );
File renamed without changes.
File renamed without changes.

assets/js/scripts/common.js renamed to assets/js/src/core.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const common = (($) => {
1+
const core = (($) => {
22
'use strict';
33

44
/**
@@ -28,4 +28,4 @@ const common = (($) => {
2828

2929
})(jQuery);
3030

31-
jQuery(common.ready);
31+
jQuery(core.ready);

0 commit comments

Comments
 (0)