Skip to content

Instantly share code, notes, and snippets.

@Eternal-tears
Last active August 29, 2015 14:03
Show Gist options
  • Save Eternal-tears/fbc83eeb7eb073210d9f to your computer and use it in GitHub Desktop.
Save Eternal-tears/fbc83eeb7eb073210d9f to your computer and use it in GitHub Desktop.
WordPressテーマ開発用Gruntfile
'use strict';
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
dir: {
bin:'dev', //→開発テーマ=作業フォルダ
release:'Lovelog_ver36', //→自分用のテーマ
js: 'js', //→JSフォルダ
css: 'css', //→cssフォルダ
img:'images', //→画像フォルダ
sass:'scss', //→scssフォルダ
blog:'Lovelog_ver36_blog', //→配布用テーマ
project:'Lovelog_ver36_dev', //→開発環境ごと渡すテーマ
bower:'bower_components', //→foundation5フォルダ一式
},
uglify: {
min: { //保留フォルダ/js/全てのjsファイルを圧縮します。
expand: true,
cwd: '<%= dir.release %>/<%= dir.js %>/',
src: ['**/*.js'],
dest: '<%= dir.release %>/<%= dir.js %>/'
},
foundation:{ //保留フォルダ/bower_components/foundationフォルダ内にある全てのjsファイルを圧縮します。
expand: true,
cwd: '<%= dir.release %>/<%= dir.bower %>/foundation',
src: ['**/*.js','!**/foundation.min.js'],
dest: '<%= dir.release %>/<%= dir.bower %>/foundation'
},
modernizr:{ //保留フォルダ/bower_components/modernizrフォルダ内にある全てのjsファイルを圧縮します。
expand: true,
cwd: '<%= dir.release %>/<%= dir.bower %>/modernizr',
src: ['modernizr.js'],
dest: '<%= dir.release %>/<%= dir.bower %>/modernizr'
}
},
csscomb:{
dev:{
expand: true,
cwd: '<%= dir.release %>/',
src: ['*.css'],
dest: '<%= dir.release %>/'
}
},
cssmin: {
all: { //全てのCSSファイルを圧縮します。
expand: true,
cwd: '<%= dir.release %>/', //ファイル元
src: ['*.css'], //全てのCSSファイル
dest: '<%= dir.release %>/' //圧縮したファイルの保存先
}
},
copy: {
files: { //開発フォルダ内のbower_componentsフォルダを保留フォルダにコピー
expand:true,
cwd:'<%= dir.bin %>/<%= dir.bower %>/',
src:['**'],
dest:'<%= dir.release %>/<%= dir.bower %>/'
},
files2: { //開発フォルダ内のlanguagesフォルダを保留フォルダにコピー
expand:true,
cwd:'<%= dir.bin %>/languages/',
src:['**'],
dest:'<%= dir.release %>/languages/'
},
php: { //開発フォルダ内の全てのPHPファイルを保留フォルダにコピー
expand: true,
cwd: '<%= dir.bin %>/',
src: ['**/*.php'],
dest: '<%= dir.release %>/'
},
css: { //開発フォルダ内の全てのCSSファイルを保留フォルダにコピー
expand: true,
cwd: '<%= dir.bin %>/',
src: ['**.css'],
dest: '<%= dir.release %>/'
},
images: { //開発フォルダ内のimages内の全ての画像を保留フォルダにコピー
expand: true,
cwd: '<%= dir.bin %>/',
src: ['images/**'],
dest: '<%= dir.release %>/'
},
js: { //開発フォルダ内のjs内の全てのjsファイルを保留フォルダにコピー
expand: true,
cwd: '<%= dir.bin %>/',
src: ['js/**'],
dest: '<%= dir.release %>/'
},
allcopyhome: {
expand:true,
cwd:'<%= dir.release %>',
src:['**'],
dest:'../<%= dir.release %>'
},
allcopyblog: {
expand:true,
cwd:'<%= dir.release %>',
src:['**'],
dest:'../<%= dir.blog %>'
},
allcopydev: {
expand:true,
cwd:'./',
src:['**'],
dest:'<%= dir.project %>/'
},
},
clean: {
deleteReleaseFolder: {
src: '<%= dir.release %>/'
},
deleteReleaseFolderblog: {
src: '<%= dir.blog %>/'
},
deleteReleaseFolderdev: {
src: '<%= dir.project %>/'
},
deletebower:{
src: [
'<%= dir.release %>/<%= dir.bower %>/fastclick/',
'<%= dir.release %>/<%= dir.bower %>/jqueryplaceholder/',
'<%= dir.release %>/<%= dir.bower %>/jquery.cookie/',
'<%= dir.release %>/<%= dir.bower %>/modernizr/feature-detects/',
'<%= dir.release %>/<%= dir.bower %>/modernizr/media/',
'<%= dir.release %>/<%= dir.bower %>/modernizr/test/',
'<%= dir.release %>/<%= dir.bower %>/modernizr/grunt.js',
'<%= dir.release %>/<%= dir.bower %>/jquery/bower.json',
'!<%= dir.release %>/<%= dir.bower %>/jquery/dist/jquery.min.map',
'<%= dir.release %>/<%= dir.bower %>/jquery/dist/jquery.js',
'<%= dir.release %>/<%= dir.bower %>/jquery/src/',
'<%= dir.release %>/<%= dir.bower %>/jquery-placeholder/'
]
},
deletefoundationhome:{
src: [
'<%= dir.release %>/<%= dir.bower %>/foundation/css/',
'<%= dir.release %>/<%= dir.bower %>/foundation/scss/',
'<%= dir.release %>/<%= dir.bower %>/foundation/bower.json',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation.min.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.abide.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.accordion.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.alert.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.clearing.js',
//'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.dropdown.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.equalizer.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.interchange.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.joyride.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.magellan.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.offcanvas.js',
//'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.orbit.js',
//'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.reveal.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.slider.js',
//'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.tab.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.tooltip.js',
//'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.topbar.js',
]
},
deletefoundationblog:{
src: [
'<%= dir.release %>/<%= dir.bower %>/foundation/css/',
'<%= dir.release %>/<%= dir.bower %>/foundation/scss/',
'<%= dir.release %>/<%= dir.bower %>/foundation/bower.json',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation.min.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.abide.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.accordion.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.alert.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.clearing.js',
//'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.dropdown.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.equalizer.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.interchange.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.joyride.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.magellan.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.offcanvas.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.orbit.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.reveal.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.slider.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.tab.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.tooltip.js',
//'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/foundation.topbar.js',
]
},
deletefoundatinplugin:{
src:[
'<%= dir.release %>/<%= dir.bower %>/foundation/**/*.js',
'!<%= dir.release %>/<%= dir.bower %>/foundation/**/*.all.js',
'<%= dir.release %>/<%= dir.bower %>/foundation/js/foundation/'
]
},
deleteallhome:{
src:[
'<%= dir.release %>/<%= dir.bower %>/**/',
'<%= dir.release %>/**/*.js',
'<%= dir.bin %>/<%= dir.sass %>/style-home.scss',
'!<%= dir.release %>/<%= dir.js %>/bower.all.js',
'!<%= dir.release %>/<%= dir.js %>/in-function.js',
'!<%= dir.release %>/<%= dir.js %>/in-function-mobile.js',
]
},
deleteallblog:{
src:[
'<%= dir.release %>/<%= dir.bower %>/**/',
'<%= dir.release %>/**/*.js',
'<%= dir.release %>/home.php',
'<%= dir.release %>/reference.php',
'<%= dir.release %>/content-category.php',
'<%= dir.bin %>/<%= dir.sass %>/style-blog.scss',
'!<%= dir.release %>/<%= dir.js %>/bower.all.js',
'!<%= dir.release %>/<%= dir.js %>/in-function.js',
'!<%= dir.release %>/<%= dir.js %>/in-function-mobile.js',
]
},
deletealldev:{
src:[
'<%= dir.project %>/<%= dir.release %>/**/',
'<%= dir.project %>/<%= dir.blog %>/**/',
]
},
deletedevtheme:{
src:[
'<%= dir.release %>/**/',
'<%= dir.bin %>/style.css',
]
},
},
concat: {
jquery: {
src: ['<%= dir.release %>/<%= dir.bower %>/jquery/**/*.js','<%= dir.release %>/<%= dir.bower %>/modernizr/*.js','<%= dir.release %>/<%= dir.bower %>/foundation/js/**/*.js'], //結合する対象ファイル
dest: '<%= dir.release %>/<%= dir.js %>/bower.all.js', //結合してリネームしたファイルの保存先
},
othershome: {
src: ['<%= dir.release %>/<%= dir.js %>/jquery.sticky-kit.min.js','<%= dir.release %>/<%= dir.js %>/jQueryAutoHeight.js','<%= dir.release %>/<%= dir.js %>/in-function.js'],
dest: '<%= dir.release %>/<%= dir.js %>/in-function.js',
},
othersblog: {
src: ['<%= dir.release %>/<%= dir.js %>/jquery.sticky-kit.min.js','<%= dir.release %>/<%= dir.js %>/jQueryAutoHeight.js','<%= dir.release %>/<%= dir.js %>/in-function-blog.js'],
dest: '<%= dir.release %>/<%= dir.js %>/in-function.js',
},
sasshome: {
src: ['<%= dir.bin %>/<%= dir.sass %>/_home-theme-name.scss','<%= dir.bin %>/<%= dir.sass %>/style.scss','<%= dir.bin %>/scss/_home.scss',],
dest: '<%= dir.bin %>/<%= dir.sass %>/style-home.scss',
},
sassblog: {
src: ['<%= dir.bin %>/<%= dir.sass %>/_blog-theme-name.scss','<%= dir.bin %>/<%= dir.sass %>/style.scss','<%= dir.bin %>/scss/_blog.scss',],
dest: '<%= dir.bin %>/<%= dir.sass %>/style-blog.scss',
},
},
sass: {
disthome: {
files: {
'<%= dir.bin %>/style.css': '<%= dir.bin %>/<%= dir.sass %>/style-home.scss'
}
},
distblog: {
files: {
'<%= dir.bin %>/style.css': '<%= dir.bin %>/<%= dir.sass %>/style-blog.scss'
}
},
},
pngmin: {
compile:{
options: {
ext:'.png', //デフォルトでは拡張子の前に、【-fs8】がついて、画像名+-fs8+.pngになるので、デフォルト値を取る。
force: true //同名の既存の画像ファイルがある場合、上書きするか否か。デフォルト値はfalseなので上書きされない設定になっているので、trueにする。
},
files: [{
expand: true,
src: ['**/*.png'], //対象ファイル
cwd: '<%= dir.bin %>/images/', //圧縮する対象の画像フォルダ先
dest: '<%= dir.release %>/images/' //圧縮した画像の保存先
}]
}
},
});
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-csscomb');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-pngmin');
grunt.registerTask('default', ['cssmin']);
//私用テーマ作成用
grunt.registerTask('home', ['clean:deleteReleaseFolder','concat:sasshome','sass:disthome','copy:files','copy:files2','copy:php','copy:css','copy:js','pngmin','cssmin:all','clean:deletebower','clean:deletefoundationhome','uglify','concat:jquery','concat:othershome','clean:deleteallhome','copy:allcopyhome','clean:deletedevtheme']);
//配布用テーマ作成用
grunt.registerTask('blog', ['clean:deleteReleaseFolderblog','concat:sassblog','sass:distblog','copy:files','copy:files2','copy:php','copy:css','copy:js','pngmin','cssmin:all','clean:deletebower','clean:deletefoundationblog','uglify','pngmin','concat:jquery','concat:othersblog','clean:deleteallblog','copy:allcopyblog','clean:deletedevtheme']);
//開発環境ごと渡す用
grunt.registerTask('dev', ['clean:deleteReleaseFolderdev','copy:allcopydev','clean:deletealldev']);
//ローカル確認用私用テーマ作成用…非圧縮
grunt.registerTask('local-home', ['clean:deleteReleaseFolder','concat:sasshome','sass:disthome','copy:files','copy:files2','copy:php','copy:css','copy:images', 'copy:js','csscomb','clean:deletebower','clean:deletefoundationhome','concat:jquery','concat:othershome','clean:deleteallhome','copy:allcopyhome','clean:deletedevtheme']);
//ローカル確認用配布用テーマ作成用…非圧縮
grunt.registerTask('local-blog', ['clean:deleteReleaseFolderblog','concat:sassblog','sass:distblog','copy:files','copy:files2','copy:php','copy:css','copy:images','copy:js','csscomb','clean:deletebower','clean:deletefoundationblog','concat:jquery','concat:othersblog','clean:deleteallblog','copy:allcopyblog','clean:deletedevtheme']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment