This README documents the steps needed to create a local environment with Pattern Lab + Wordpress install running side-by-side.
To serve as a starterkit for new Wordpress projects by providing the developer with a starterkit for Pattern Lab, and a starter child theme.
- Node
- npm
- Gulp. It is recommended to upgrade to Gulp 4. See Prerequisites for installing Gulp Edition of Pattern Lab for more information.
/patternlab/
- Contains Pattern Lab./site/
- Contains Wordpress./src/
- Contains shared assets such as sass and js files.gulpfile.js
- Runs tasks that interact with patternlab, site, and src.package.json
- Installs dependencies to get started.
Pattern Lab and Wordpress are installed in subdirectories from the root of the project.
The third directory, /src/
is where developers will work inside to build the project's patternlab and wordpress child theme.
In the root of the project is gulpfile.js
. This file will run tasks that will compile sass and js and prepare them to be distributed into Pattern Lab and Wordpress.
Before doing anything else, navigate to the package.json file included in the project, and change the value of "name" to whatever you want your theme folder to be called. If you don't complete this before running the initial "gulp init" task, you may encounter some errors.
Pattern Lab is a static site generator. There are many different ways to build a Pattern Lab site.
The core of Pattern Lab is available in PHP or Node - it us up to developers and their teams to choose which language they want to use to generate the static site.
This tutorial focuses on how to install the Gulp edition of Pattern Lab, which is written in Node.
The Gulp edition uses Gulp tasks inside the Pattern Lab directory to generate the site when its source files change.
In the future, we hope to automate the download and configuration of Pattern Lab.
It's highly recommended that you install gulp globally.
Also, it's recommended you upgrade to Gulp 4, which may require a new global install of the Gulp command line interface. Learn more by referring to the Prerequisites for installing Gulp Edition of Pattern Lab. Here is an excellent guide on how to upgrade to Gulp 4.
There are two options for getting Pattern Lab
- Download the repo from the github page, without cloning the repository
- Include the repo from the github page as a submodule in your project
Go to the https://github.com/pattern-lab/edition-node-gulp to download the Repo or click this link to download the master branch in a .zip file.
You may also include it as a git submodule. In the root of your repo for your new project, enter git submodule add https://github.com/pattern-lab/edition-node-gulp.git
. This creates a new directory in the root of your project called edition-node-gulp
that contains the Pattern Lab folders.
Rename edition-node-gulp
to patternlab
by using the git mv
command. For example, git mv edition-node-gulp patternlab
renames the git submodule edition-node-gulp
to simply patternlab
.
In the command line, change to the directory that contains Pattern Lab. Example: From the root of the project, run cd patternlab
.
Run npm install
to install Pattern Lab.
This tutorial assumes Wordpress will be installed in the /site/
subdirectory from the root of the project. It is recommended to install Wordpress in a subdirectory to keep the project root neat and tidy.
Please note that this is not a requirement. If you wish to install Wordpress in the root of the project rather than a subdirectory, the gulpfile.js
file will need to be modified to update the path variables defined at the top of the file.
There are two options to install Wordpress in a subdirectory:
- Place the Wordpress files in the subdirectory,
/site/
and run the installer so the domain resolves atwww.domain.com/site
. - Place the Wordpress files in the root of the project and run the installer so the domain resolves at
www.domain.com
. The Codex demonstrates this method in the article, Giving Wordpress Its Own Directory.
This tutorial assumes Option 1. If this doesn't work for your workflow, you can follow the steps from the codex article referenced in Option 2.
Once Wordpress is installed in the subdirectory, follow these steps:
- Login to Wordpress, go to Settings > General, and modify the field
Site Address (URL)
from "http://www.yourdomain.com/site" to "http://www.yourdomain.com". Do not hit save yet. - Navigate to the
/site/
directory, duplicateindex.php
and.htaccess
files so they readindex-copy.php
and.htaccess-copy
. - Move the duplicated files into the root of the project.
- Edit
index-copy.php
by modifying:require( dirname( __FILE__ ) . '/wp-blog-header.php' );
to berequire( dirname( __FILE__ ) . '/site/wp-blog-header.php' );
- Save
index-copy.php
. - While in the root of the project, rename
index-copy.php
and.htaccess-copy
toindex.php
and.htaccess
. - Go back to the open Wordpress screen and click save.
- Go to Settings > Permalinks and re-save.
- Giving Wordpress Its Own Directory
- How and Why Install WordPress Core in a Subdirectory - for wp cli users
After Wordpress is installed, download the em-base parent theme and place it into the Wordpress themes directory
Now that Pattern Lab and Wordpress are installed in their own directories, the next steps are to:
-
Modify
gulpfile.js
in the root:browserSync.init({ proxy: "domain.dev", // Rename this to your desired domain name port: 3333 });
-
Run
npm install
from the root of the project to install global project dependences -
Run
gulp init
. This command executes the following:- Downloads all vendor plugins such as picturefill, colorbox, slick carousel, etc.
- Distributes vendor plugins into Pattern Lab and Wordpress, grouped into header scripts and footer scripts.
- Executes the default
gulp
command for you which compiles sass and js, distribute those assets into Patternlab and Wordpress, builds the Pattern Lab site, and spins up two servers: one for Pattern Lab, and one for your site.
You are now ready to use Pattern Lab and Wordpress, while managing the shared assets in one location and having it push to both environments.
Note that there are two Gulp files. One is inside the root of the project, and one comes with Pattern Lab node gulp edition.
It is important to not modify the gulpfile inside the Pattern Lab directory because these assets are ignored in the repository.
Instead, developers, can run any command from any gulpfile in any directory using the --gulp
flag when executing a gulp command.
Example: From the command line in the root of the project, run "gulp --gulpfile /patternlab/gulpfile.js patternlab:build
to run a task defined in the Pattern Lab gulpfile.
Any of the default commands can be run as long as the --gulpfile
flag is present, followed by the path of the gulpfile you wish to call a task from.