- This was creator for folks at my local WordPress Meetup group to get them started using some modern frontend developer tooling.
- This is for local development of a WordPress theme using something like:
- Sass (
.scss) - Autoprefixer (automatically creates css rules for
IE10+compatibility) - Modern JavaScript ES2015+ (compiles to ES5 for
IE10+compatibility)
- Open your terminal,
cdinto your themes directory- (e.g.
cd ~/Local\ Sites/project/app/public/wp-content/themes)
- (e.g.
- Clone the repo
git clone https://github.com/mizner/Creator - Run
yarn install(ornpmalternatives) ... I highly recommend yarn. - To build assets (css & javascript) run
gulp build- Note:
.scssfiles will pre-process to.cssfiles output in the/distfolder - Note: All
.jsfiles get combined and minified to one file output in the/distfolder
- Note:
- Open
gulpfile.jsand make surelocalUriis changed fromhttp://wordpress.devto whatever you local site is e.glocalhost:8000,http://mysite.dev, etc. - Now the awesome part, run
gulp watch- Note: This will open your browser to
localhost:3000(probably) and watch for changes you make to theme files. - Note:
.jsand.phpfiles with cause the page to reload - Awesome Note:
.scssfiles changes will inject the new sites into the site without reloading (well... 99% of the time).
- Note: This will open your browser to
- Clean up the files in the
assets/scripts(there's just some simple code inside as an example) - Have fun writing
.scssand watching your changes happen immediately
- The
style.cssfile is only being loaded on the backend to allow it to be activated. Nocsschanges here will effect the frontend. functions.php(starting at line123) has been lightly modified to enqueue 3 new files- Our main
cssfile that is dynamically created viagulp - Our main
jsfile that is dynamically created viagulp - A WooCommerce
cssfile (if WooCommerce exists) that is dynamically created viagulp
- Our main
- Copy
package.jsonandgulpfile.jsinto your existing theme. - Create a
assetsfolder with two subdirectory folders insidescriptsandstyle - Create a
main.jsfile in thescriptsfolder - Create a
main.scssfile in thestylefolder - Run
yarn installafter you'vecdinto the theme directory - Make sure you've changed the
url - Modify your
functions.phpto enqueue thecssandjsfiles
Example:
function gulp_enqueues() {
$childtheme_css = get_stylesheet_directory_uri() . '/dist/main.min.css'; // Use if not a child theme
$theme_css = get_template_directory_uri() . '/dist/main.min.css'; // Use if not a child theme
wp_enqueue_style( 'gulp-style', $theme_css );
$childtheme_js = get_stylesheet_directory_uri() . '/dist/main.min.js'; // Use if not a child theme
$theme_js = get_template_directory_uri() . '/dist/main.min.js'; // Use if not a child theme
wp_enqueue_script( 'gulp-script', $theme_js, [ 'jquery' ], '1.0', true );
}
add_action( 'wp_enqueue_scripts', 'gulp_enqueues' );