#Basic WP Localhost Dev Env ######(Localhost Development Environment)
- Localhost environment (Bitnami, MAMP, WAMP, XAMPP)
- Local install of WP
- Code Editor (NetBeans IDE, Sublime Text 3)
- Browser with developer tools (Chrome F12)
- Version control (git + GitHub)
Why? Variables + Mixins
sass-lang.com/guide
bourbon.io
- A Sass mixin librarygithub.com/nDmitry/grunt-autoprefixer
- Auto-prefixer for Grunt
Why? It listens to a folder and runs events when a file is changed
- Preprocessed .SCSS file is changed by the developer
- Run Sass -> Compiled .CSS file
- Run Autoprefixer -> Final .CSS file (with browser prefixes)
Mac:
- Install Node.js if you don't have it (I didn't)
- Change permissions:
sudo chown -R $USER /usr/local
sudo
= adminchown
= change owner-R
= recursively$USER
= to the current user/usr/local
= over this folder (node is here and will put Grunt here)- Install Grunt:
npm install -g grunt-cli
npm
= Node package managerinstall
= install-g
= globallygrunt-cli
= Grunt- Install Sass:
sudo gem install sass
gem
= Ruby gem
- Navigate to the project folder in Terminal
cd Desktop/...
- Initialize project and set parameters
npm init
name:
version:
description:
entry point:
(index.html)test command:
git repository:
keywords:
author:
license:
- Now you see
package.json
in the folder (can removescripts:
if you want) npm install grunt-contrib-sass --save-dev
- installs 2 new packages
--save-dev
= only install in THIS folder (not globally)- Package 1 (package.json):
grunt:
- Package 2 (package.json):
grunt-contrib-sass:
npm install grunt-contrib-watch --save-dev
- Package 3 (package.json):
grunt-contrib-watch:
- Be sure the
Gruntfile.js
(below) is in the folder - Type
grunt
in Terminal to start watching
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'), // Tell Grunt where the package file is
/**
* Sass
*/
sass: { // First task Grunt runs
dev: { // First Sass task
options: {
style: 'expanded', // Create 'expanded' (human-readable) stylesheet
sourcemap: 'none', // No sourcemap (tells us where all different components come from)
},
files: { // Second Sass task (grab these files and...)
'css/style.css': 'scss/style.scss' // Grab style.scss from SCSS folder and compile into 'style.css' in the root folder
}
},
dist: { // What we're shipping with the Theme (a minimized style.css)
options: {
style: 'compressed', // Create 'compressed' (minimized) stylesheet
sourcemap: 'none', // No sourcemap (tells us where all different components come from)
},
files: { // Second Sass task (grab these files and...)
'css/ style.min.css': 'scss/style.scss' // Grab style.scss from SCSS folder and compile into 'style.css' in the root folder
}
}
},
/**
* Autoprefixer
*/
autoprefixer: {
options: {
browsers: ['last 2 versions']
},
// prefix all files
multiple_files: {
expand: true,
flatten: true,
src: 'css/*.css',
dest: '' // destination = root folder
}
},
/**
* Watch task
*/
watch: { // First Grunt task
css: {
files: '**/*.scss', // Watch all files with a .scss suffix
tasks: ['sass', 'autoprefixer'] // Run the Sass tasks on those items (can be an array of tasks)
}
},
});
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.registerTask('default', ['watch']); // Name here is set to 'default' but can be anything
}
- Open code editor with project
- Open Terminal and
cd
to project folder - Type
grunt
to start watching the folder - Code
- In Terminal, type
CTRL + C
to stop Grunt clear
cleans the Terminal window
node_modules
.npm-debug.log
tmp
.sass-cache
*.css.map
- Get a localhost version of WordPress going
- Populate the install with Theme Test Data
- Get _s Starter Theme (sass version)
- Dump theme folder into
wp-content/themes
- Activate Theme
- Initialize git in the project folder
git init
(or create a repo on GitHub and clone it before step 4) - Create
.gitignore
file (ignore Node and SCSS files) - Use Terminal to navigate to project folder
cd ...
- Create package.json file
npm init
(entry point: index.php
) - Install Sass
npm install grunt-contrib-sass --save-dev
- Install Watch
npm install grunt-contrib-watch --save-dev
- Install Autoprefixer
npm install grunt-autoprefixer --save-dev
- Rename original
style.css
tostyle-OLD.css
(save the original just in case)
- or, use version control (
git
) andbranch
away to work, thenmerge
back in when ready - To make Grunt not compress the WP Theme header comment, add a
!
to the first comment instyle.scss
that defines the theme after the/*
- Creat
Gruntfile.js
- In
sass/layout
folder, create_flex.scss
(or other code that needs prefixed)
.site-content { display: flex; }
.content-area { flex: 2; }
.site-content .widget-area { flex: 1; }
- Place flexbox (prefixed) code in
style.scss
(@import "layout/flex";
) - Run
grunt
- Modify code