You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 3, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: gulpconfig.js
+3-4Lines changed: 3 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -53,14 +53,14 @@ module.exports = {
53
53
,chunks: {// Chunks are arrays of paths or globs matching a set of source files; this way you can organize a bunch of scripts that go together into pieces that can then be bundled (above)
54
54
// The core chunk is loaded no matter what; put essential scripts that you want loaded by your theme in here
55
55
core: [
56
-
modules+'timeago/jquery.timeago.js'
56
+
modules+'timeago/jquery.timeago.js'// The modules directory contains packages downloaded via npm
57
57
,src+'js/responsive-menu.js'
58
58
,src+'js/core.js'
59
59
]
60
60
// The pageloader chunk provides an example of how you would add a user-configurable feature to your theme; you can delete this if you wish
61
61
// Have a look at the `src/inc/assets.php` to see how script bundles could be conditionally loaded by a theme
62
62
,pageloader: [
63
-
modules+'html5-history-api/history.js'// The modules directory contains packages downloaded via npm
src: [src+'js/**/*.js']// Linting checks the quality of the code; we only lint custom scripts, not those under the various modules, so we're relying on the original authors to ship quality code
Copy file name to clipboardExpand all lines: readme.md
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,6 +38,7 @@ If you're already up and running with most of the usual Node ecosystem tools thi
38
38
* Install all dependencies by running `npm install`. This will fetch all dependencies listed in `package.json` (which includes front-end JavaScript packages and back-end tools like Gulp plugins and [BrowserSync](http://www.browsersync.io/)).
39
39
*[BrowserSync](http://www.browsersync.io/) setup: assuming you have a local development environment setup all you should need to do is enter the URL into the `proxy` setting in `gulpconfig.js`. Why use BrowserSync? It's fast, awesome, and allows for simultaneous responsive development across multiple devices.
40
40
*[LiveReload](http://livereload.com/) setup: install a browser extension for [Chrome](https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei) or Firefox. Why use LiveReload? It does the job without complications or additional setup after the extension is installed.
41
+
* This build process assumes you're up and running with [source maps for both JavaScript and Sass](http://blog.teamtreehouse.com/introduction-source-maps). You may need to configure your browser or debugging environment to make sense of the minified files generated by Gulp!
41
42
* Run `gulp` and start hacking!
42
43
43
44
@@ -53,7 +54,7 @@ There are two components worth a closer look:
53
54
* The script variable and enqueuing functions in `src/inc/assets.php`; these are tightly coupled with the output of the build process.
54
55
* The theme configuration pattern described in `functions.php` and `functions-config-defaults.php`.
55
56
56
-
Whether you use anything from this built-in theme is entirely up to you. If you prefer to start working with your own theme just drop it in. You may need to go into `gulpconfig.js` and modify paths and glob matching patterns but this is designed to be fairly easy and straight-forward with lots of comments to point you in the right direction.
57
+
Whether you use anything from this built-in theme is entirely up to you. If you prefer to start working with your own theme just drop it in. You will probably need to modify paths and glob matching patterns in `gulpconfig.js`but it is designed to be fairly easy and straight-forward with lots of comments to point you in the right direction.
57
58
58
59
59
60
@@ -82,7 +83,7 @@ Configuration is handled by a single file: `gulpconfig.js`. If you leave the dir
82
83
*[BrowserSync](http://www.browsersync.io/) settings: if you are developing on a local web server you will want to enter the URL into `browsersync.proxy` and then change `watch.watcher` to `browsersync` to take it for a test drive. You'll know it's working when you run `gulp` and a new browser opens with a live copy of your web site. Make changes to any of the Sass files and they should be shown on the page almost immediately. Of course, BrowserSync really shines when you connect a mobile device to your development server, but for that you're on your own ;)
83
84
* Script settings: draw your attention to `scripts.bundles` and `scripts.chunks`. This feature is essentially a poor man's [Browserify](http://browserify.org/) or [Webpack](https://webpack.github.io/). By defining different "chunks" (script files that combine to provide a particular feature) and "bundles" (chunks that combine to provide feature sets) you can generate an assortment of files that can be efficiently and intelligently loaded through your WordPress theme. This approach has its limitations, of course, particularly when dependencies are shared between scripts, but it should be of use to many WordPress theme developers.
84
85
85
-
Interested in adding new Gulp plugins to your build system? A full tutorial is out of scope for this project but it really shouldn't be all that hard to figure out. In brief, install a plugin with `npm install [package] --save-dev`, require it in a suitable task file, add something to the configuration file if needed, and drop it into the pipeline somewhere. Some types of plugin are particularly easy to add, for instance anything listed on the [postcss.parts](http://postcss.parts/) web site (install, require, and add to the `processor` variable in `./gulpfile.js/tasks/styles.js`).
86
+
Interested in adding new Gulp plugins to your build system? A full tutorial is out of scope for this project but it really shouldn't be all that hard to figure out. In brief, install a plugin with `npm install [package] --save-dev`, require it in a suitable task file, add something to the configuration file if needed, and drop it into the pipeline somewhere. Some types of plugin are particularly easy to add, for instance anything listed on the [postcss.parts](http://postcss.parts/) web site (install, require, and add to the `processor` variable in `/gulpfile.js/tasks/styles.js`).
86
87
87
88
88
89
@@ -131,7 +132,9 @@ Like images, PHP (and language) files can go anywhere under `src` and will be co
131
132
132
133
133
134
134
-
## EXAMPLE INTEGRATION
135
+
## EXAMPLE INTEGRATIONS
136
+
137
+
The bare bones theme included in this starter kit integrates two external JavaScript projects: [timeago](http://timeago.yarp.com/) (which facilitates human-readable timestamps) and [WP AJAX Page Loader](https://github.com/synapticism/wp-ajax-page-loader) (a lightweight and intelligent infinite scroll script). Have a look at the `/src/inc/assets.php` file and `gulpconfig.js` to see how this was accomplished. Timeago required only `npm install -d timeago`, an extra line in `gulpconfig.js`, and initialization in `/src/js/core.js`. Integrating the other script was much more involved; you'll have to browse the source and see for yourself.
135
138
136
139
Let's say you run across a cool project like [Headroom.js](http://wicky.nillia.ms/headroom.js/) and decide you'd like to try it out. Here's how you would do that with the tools and workflow outlined in this repo:
Copy file name to clipboardExpand all lines: src/inc/assets.php
+23-19Lines changed: 23 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -1,60 +1,64 @@
1
1
<?php// ==== ASSETS ==== //
2
2
3
3
// Now that you have efficiently generated scripts and stylesheets for your theme, how should they be integrated?
4
-
// This file walks you through the approach I use but you are free to approach this any way you like
4
+
// This file walks you through the approach I use but you are free to do this any way you like
5
5
6
6
// Enqueue front-end scripts and styles
7
7
functionvoidx_enqueue_scripts() {
8
8
9
-
$script_name = ''; // Empty by default, may be populated by conditionals below
9
+
$script_name = ''; // Empty by default, may be populated by conditionals below; this is used to generate the script filename
10
10
$script_vars = array(); // An empty array that can be filled with variables to send to front-end scripts
11
-
$script_handle = 'voidx'; // A generic script handle
12
-
$suffix = '.min'; // The suffix for minified scripts
13
-
$ns = 'wp'; // Namespace for scripts
14
-
15
-
// Load original scripts when debug mode is on; this allows for easier local development
16
-
if ( WP_DEBUG === true )
17
-
$suffix = '';
11
+
$script_handle = 'voidx'; // A generic script handle used internally by WordPress
12
+
$ns = 'wp'; // Namespace for scripts; this should match what is specified in your `gulpconfig.js` (and it's safe to leave alone)
18
13
19
14
// Figure out which script bundle to load based on various options set in `src/functions-config-defaults.php`
20
-
// Note: bundles require less HTTP requests at the expense of addition caching hits when different scripts are requested
21
-
// You could also load one main bundle on every page with supplementary scripts as needed (e.g. for commenting or a contact page)
15
+
// Note: bundles require fewer HTTP requests at the expense of addition caching hits when different scripts are requested on different pages of your site
16
+
// You could also load one main bundle on every page with supplementary scripts as needed (e.g. for commenting or a contact page); it's up to you!
17
+
18
+
19
+
20
+
// == EXAMPLE INTEGRATION == //
22
21
23
22
// An example integration using WP AJAX Page Loader; this script requires a bit more setup as outlined in the documentation: https://github.com/synapticism/wp-ajax-page-loader
24
23
$script_vars_page_loader = '';
25
24
26
25
// This conditional establishes whether the page loader bundle is loaded or not; you can turn this off completely from the theme configuration file if you wish (or just remove the code)
$script_name .= '-pageloader'; // This is used to generate the filename that the theme will serve to the user; it is additive to allow for multiple features that can be toggled in the theme configuration
29
27
30
-
global$wp_query;
28
+
// The script name is used to specify the file that the theme will serve to users
29
+
// Script names are designed to be additive (meaning you can append more script names to the end in other conditional blocks using `.= '-anotherscript'` etc.) to allow for multiple feature toggles in the theme configuration
30
+
$script_name .= '-pageloader';
31
31
32
-
// This chunk of code provisions the script with some important information it needs: What page are we on? And what is the page limit?
32
+
// This chunk of code provisions the WP AJAX Page Loader script with some important information it needs: What page are we on? And what is the page limit?
// Prepare script variables; note that these are separate from the rest of the script variables as this script requires everything in an object named `PG8Data`
37
+
// Prepare script variables; note that these are separate from the rest of the script variables as the WP AJAX Page Loader script requires everything in a specific object named `PG8Data`
37
38
$script_vars_page_loader = array(
38
39
'startPage' => $paged,
39
40
'maxPages' => $max,
40
41
'nextLink' => next_posts( $max, false )
41
42
);
42
43
} // WP AJAX Page Loader configuration ends
43
44
44
-
// Default script name
45
+
46
+
47
+
// Default script name; used when conditional blocks (above) aren't triggered
45
48
if ( empty( $script_name ) )
46
49
$script_name = '-core';
47
50
48
51
// Load theme-specific JavaScript bundles with versioning based on last modified time; http://www.ericmmartin.com/5-tips-for-using-jquery-with-wordpress/
49
52
// The handle is the same for each bundle since we're only loading one script; if you load others be sure to provide a new handle
// Script variables for WP AJAX Page Loader (these are separate from the main theme script variables due to the naming requirement; the object must be `PG8Data`)
60
+
// Script variables specific to WP AJAX Page Loader (these are separate from the main theme script variables due to the naming requirement; the object must be `PG8Data`)
61
+
// This appears and NOT in the conditional block (above) because these variables will be attached to the main script handle (which may be modified after the page loader block)
// Non-destructively merge script variables if a particular condition is met (e.g. `is_archive()` or whatever)
77
+
// Non-destructively merge script variables if a particular condition is met (e.g. `is_archive()` or whatever); useful for managing many different kinds of script variables
0 commit comments