QWp6t f6bdc7b48c Refactor build routine and switch to airbnb style (#1703)
- Relocate webpack stuff to assets/build
- Switch all js to airbnb code style
- Update webpack to v2.0 (beta)
- Update all other dependencies
- Assets manifest uses relative path as key [1]
- Code should be compatible with Node 4.5.0
- All dependencies have been updated

[1]: Previously the assets manifest would use the basename of a file path as
its key when looking up a cachebusted file. This was to be consistent with
Sage 8. This change makes it so that the relative path is used instead.

To clarify, review the following example.

Before:
```
{
  "main.js": "scripts/main_5f4bfc9a9f82291c6dea.js",
  "main.css": "styles/main_5f4bfc9a9f82291c6dea.css",
  "customizer.js": "scripts/customizer_5f4bfc9a9f82291c6dea.js"
}
```

After:
```
{
  "scripts/main.js":"scripts/main_5f4bfc9a9f82291c6dea.js",
  "styles/main.css":"styles/main_5f4bfc9a9f82291c6dea.css",
  "scripts/customizer.js":"scripts/customizer_5f4bfc9a9f82291c6dea.js"
}
```
2016-09-04 19:13:16 -07:00
2016-02-14 22:48:03 +01:00
2016-08-30 00:15:06 -06:00
2013-11-07 21:28:52 -06:00
2016-08-30 00:15:06 -06:00

Sage

Packagist devDependency Status Build Status

Sage is a WordPress starter theme with a modern development workflow.

Write stylesheets with Sass, automatically check your JavaScript for errors, optimize images, enable synchronized browser testing, and more.

Features

  • Webpack is used as a build tool for compiling stylesheets, checking for JavaScript errors, optimizing images, and concatenating and minifying files
  • BrowserSync for keeping multiple browsers and devices synchronized while testing, along with injecting updated CSS and JS into your browser while you're developing
  • Bootstrap
  • Template inheritance with the theme wrapper
  • ARIA roles and microformats
  • Posts use the hNews microformat
  • Multilingual ready and over 30 available community translations

Install the Soil plugin to enable additional recommended features:

  • Load jQuery from the jQuery CDN
  • Cleaner WordPress markup
  • Cleaner HTML output of navigation menus
  • Root relative URLs
  • Nice search
  • Google Analytics snippet from HTML5 Boilerplate
  • Move all JS to the footer
  • Disable trackbacks and pingbacks

See a complete working example in the roots-example-project.com repo.

Requirements

Make sure all dependencies have been installed before moving on:

Theme installation

From the command line, run the following commands from the root of your WordPress site (where composer.json exists). These instructions assume you're using a Bedrock-based WordPress setup. If you're using Vagrant, make sure to run these commands from the Vagrant box (vagrant ssh). Create a new theme based on Sage by using Composer's create-project:

# @ example.com/site
$ composer create-project roots/sage web/app/themes/your-theme-name 9.0.0-alpha.1

Then activate the theme via wp-cli:

# @ example.com/site
$ wp theme activate your-theme-name

Theme structure

themes/theme-name/        # → Root of your Sage based theme
├── assets                # → Front-end assets
│   ├── config.json       # → Settings for compiled assets
│   ├── fonts/            # → Theme fonts
│   ├── images/           # → Theme images
│   ├── scripts/          # → Theme JS
│   └── styles/           # → Theme stylesheets
├── composer.json         # → Autoloading for `src/` files
├── composer.lock         # → Composer lock file (never manually edit)
├── dist/                 # → Built theme assets (never manually edit)
├── functions.php         # → Never manually edit
├── index.php             # → Never manually edit
├── node_modules/         # → Node.js packages (never manually edit)
├── package.json          # → Node.js dependencies and scripts
├── screenshot.png        # → Theme screenshot for WP admin
├── src/                  # → Theme PHP
├── style.css             # → Theme meta information
├── templates/            # → Theme templates
│   ├── layouts/          # → Base templates
│   └── partials/         # → Partial templates
├── vendor/               # → Composer packages (never manually edit)
├── watch.js              # → Webpack/BrowserSync watch config
└── webpack.config.js     # → Webpack config

Theme setup

Edit src/lib/setup.php to enable or disable theme features, setup navigation menus, post thumbnail sizes, post formats, and sidebars.

Theme development

Sage uses Webpack as a build tool and npm to manage front-end packages.

Install dependencies

From the command line on your host machine (not on your Vagrant development box), navigate to the theme directory then run npm install:

# @ example.com/site/web/app/themes/your-theme-name
$ npm install

You now have all the necessary dependencies to run the build process.

Available build commands

  • npm run build — Compile and optimize the files in your assets directory
  • npm run watch — Compile assets when file changes are made, start BrowserSync session
  • npm run build:production — Compile assets for production

Using BrowserSync

To use BrowserSync during npm watch you need to update devUrl at the bottom of assets/config.json to reflect your local development hostname.

For example, if your local development URL is https://project-name.dev you would update the file to read:

...
  "devUrl": "https://project-name.dev",
...

If you are not using Bedrock, you should also update publicPatch to reflect your folder structure.

If your theme is placed in a folder called sage then in a standard wordpress setup it should look like this:

...
  "output": {
    "path": "dist",
    "publicPath": "/wp-content/themes/sage/dist/"
  }
...

Documentation

Sage documentation is available at https://roots.io/sage/docs/.

Contributing

Contributions are welcome from everyone. We have contributing guidelines to help you get started.

Community

Keep track of development and community news.

Description
Customised by Bad Egg Digital
https://roots.io/bedrock/
Readme 13 MiB
Languages
PHP 49.6%
SCSS 26.8%
JavaScript 11.5%
Blade 10.4%
Dockerfile 1%
Other 0.7%