├── .gitattributes ├── .gitignore ├── gulpfile.js └── package.json /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git 28 | node_modules 29 | 30 | # ========================= 31 | # Operating System Files 32 | # ========================= 33 | 34 | # OSX 35 | # ========================= 36 | 37 | .DS_Store 38 | .AppleDouble 39 | .LSOverride 40 | 41 | # Thumbnails 42 | ._* 43 | 44 | # Files that might appear in the root of a volume 45 | .DocumentRevisions-V100 46 | .fseventsd 47 | .Spotlight-V100 48 | .TemporaryItems 49 | .Trashes 50 | .VolumeIcon.icns 51 | 52 | # Directories potentially created on remote AFP share 53 | .AppleDB 54 | .AppleDesktop 55 | Network Trash Folder 56 | Temporary Items 57 | .apdisk 58 | 59 | # Windows 60 | # ========================= 61 | 62 | # Windows image file caches 63 | Thumbs.db 64 | ehthumbs.db 65 | 66 | # Folder config file 67 | Desktop.ini 68 | 69 | # Recycle Bin used on file shares 70 | $RECYCLE.BIN/ 71 | 72 | # Windows Installer files 73 | *.cab 74 | *.msi 75 | *.msm 76 | *.msp 77 | 78 | # Windows shortcuts 79 | *.lnk 80 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | /*eslint-disable no-console */ 2 | var gulp = require("gulp"); 3 | var $ = require("gulp-load-plugins")(gulp); 4 | var browserSync = require("browser-sync"); 5 | var del = require("del"); 6 | var yaml = require("js-yaml").safeLoad; 7 | var sequence = require("run-sequence"); 8 | var fs = require("fs"); 9 | // var moment = require("moment"); 10 | // var highlight = require("highlight.js").highlightAuto; 11 | var config = { 12 | CompileDir: "build", //开发编译目录 13 | SourceDir: "src", //源码目录 14 | DeploymentDir: "production" //编译到生产目录 15 | }; 16 | var path = require("path"); 17 | 18 | 19 | //默认开发模式 20 | gulp.task("default", ["dev"], function (cb) { 21 | return sequence(["serve", "watch"], cb); 22 | }); 23 | 24 | gulp.task("clean", function () { 25 | return del([config.CompileDir, config.DeploymentDir, config.SourceDir + "/_md2html/*.*", config.SourceDir + "/includes/*.*", config.SourceDir + "/pagelist/*.*", config.SourceDir + "posts/*.*"]); 26 | }); 27 | gulp.task("serve", function () { 28 | return browserSync.init({ 29 | server: { 30 | baseDir: config.CompileDir 31 | }, 32 | port: 8080, 33 | localhost: "127.0.0.1" 34 | }); 35 | }); 36 | 37 | gulp.task("dev", ["delCompileDir"], function (cb) { 38 | return sequence("html", "pug", "sass", "js", "images", "jsx", cb); 39 | }); 40 | 41 | 42 | 43 | gulp.task("delCompileDir", function (cb) { 44 | return del([config.CompileDir], cb); 45 | }); 46 | 47 | gulp.task("reload", function (cb) { 48 | return sequence(["dev"], ["reload-browser"], cb); 49 | }); 50 | 51 | gulp.task("reload-browser", function () { 52 | return browserSync.reload(); 53 | }); 54 | 55 | gulp.task("watch", function () { 56 | return gulp.watch([config.SourceDir + "/**/*.*", "!" + config.SourceDir + "/_**/*.*"], ["reload"]); 57 | }); 58 | 59 | 60 | //compile jade 61 | gulp.task("pug", function () { 62 | return gulp.src([config.SourceDir + "/**/*.{jade,pug}", "!" + config.SourceDir + "/_**/*.*"]) 63 | .pipe($.plumber()) 64 | .pipe($.changed(config.CompileDir, { 65 | extension: ".html" 66 | })) 67 | .pipe($.pug({ 68 | pretty: true 69 | })) 70 | // .pipe(gulp.src(config.CompileDir + "/**/*.json")) 71 | // .pipe($.revCollector({ replaceReved: true })) 72 | .pipe(gulp.dest(config.CompileDir)); 73 | }); 74 | 75 | //compile html 76 | gulp.task("html", function () { 77 | return gulp.src([config.SourceDir + "/**/*.{html,json}", "!" + config.SourceDir + "/_**/*.{html,json}"]) 78 | .pipe(gulp.dest(config.CompileDir)); 79 | }); 80 | 81 | //compile sass 82 | gulp.task("sass", function () { 83 | return gulp.src([config.SourceDir + "/**/*.{css,scss}", "!" + config.SourceDir + "/_**/_*.*"]) 84 | .pipe($.plumber()) 85 | .pipe($.changed(config.CompileDir, { 86 | extension: ".css" 87 | })) 88 | .pipe($.sass()) 89 | .pipe($.autoprefixer([ 90 | "Android 2.3", 91 | "Android >= 4", 92 | "Chrome >= 20", 93 | "Firefox >= 24", 94 | "Explorer >= 8", 95 | "iOS >= 6", 96 | "Opera >= 12", 97 | "Safari >= 6" 98 | ])) 99 | // .pipe($.rev()) 100 | // .pipe($.revCollector({ replaceReved: true })) 101 | .pipe(gulp.dest(config.CompileDir)); 102 | // .pipe($.rev.manifest()) 103 | //.pipe(gulp.dest(config.CompileDir + "/cssversions")); 104 | }); 105 | 106 | //compile jsx 107 | gulp.task("jsx", function () { 108 | return gulp.src(config.SourceDir + "/**/*.jsx") 109 | .pipe($.plumber()) 110 | .pipe($.changed(config.CompileDir, { 111 | extension: ".js" 112 | })) 113 | .pipe($.react()) 114 | .pipe(gulp.dest(config.CompileDir)); 115 | }); 116 | 117 | //compile js 118 | gulp.task("js", function () { 119 | return gulp.src(config.SourceDir + "/**/*.js") 120 | .pipe($.changed(config.CompileDir, { 121 | extension: ".js" 122 | })) 123 | .pipe(gulp.dest(config.CompileDir)); 124 | }); 125 | 126 | gulp.task("library",function(){ 127 | return gulp.src() 128 | }); 129 | 130 | //images 131 | gulp.task("images", function () { 132 | return gulp.src(config.SourceDir + "/**/*.{png,jpg,gif,svg}") 133 | .pipe($.plumber()) 134 | .pipe($.changed(config.CompileDir)) 135 | .pipe(gulp.dest(config.CompileDir)); 136 | }); 137 | 138 | 139 | //用于生产环境 140 | gulp.task("deploy", ["delDeploymentDir","dev"], function () { 141 | return sequence(["imgmin"], ["cssmin"], ["jsmin"], ["htmlmin"]); 142 | }); 143 | gulp.task("delDeploymentDir", function (cb) { 144 | return del([config.DeploymentDir], cb); 145 | }); 146 | 147 | 148 | //压缩css 149 | gulp.task("cssmin", function () { 150 | return gulp.src(config.CompileDir + "/**/*.{css,json}") 151 | // .pipe($.base64({ 152 | // baseDir: config.CompileDir, 153 | // extensions: ["jpg", "jpeg", "png", "gif"], 154 | // exclude: [/\.server\.(com|net)\/dynamic\//, "--live.jpg"], 155 | // maxImageSize: 2 * 1024, // bytes 156 | // debug: true 157 | // })) 158 | .pipe($.css()) 159 | .pipe($.rev()) 160 | .pipe($.revCollector({ 161 | replaceReved: true 162 | })) 163 | .pipe(gulp.dest(config.DeploymentDir)) 164 | .pipe($.rev.manifest()) 165 | .pipe(gulp.dest(config.CompileDir + "/version/css")); 166 | }); 167 | 168 | 169 | //压缩html 170 | gulp.task("htmlmin", function () { 171 | return gulp.src(config.CompileDir + "/**/*.{html,json}") 172 | .pipe($.revCollector({ 173 | replaceReved: true 174 | })) 175 | .pipe($.htmlmin({ 176 | collapseWhitespace: true, 177 | removeComments: true 178 | })) 179 | .pipe(gulp.dest(config.DeploymentDir)); 180 | }); 181 | 182 | 183 | //压缩图片 184 | gulp.task("imgmin", function () { 185 | return gulp.src(config.CompileDir + "/**/*.{png,jpg,gif,svg}") 186 | .pipe($.imagemin({})) //开发环境用起来太慢 打包生产环境时使用 187 | .pipe($.rev()) 188 | .pipe(gulp.dest(config.DeploymentDir)) 189 | // .pipe(upload({qn: qnOptions})) 190 | .pipe($.rev.manifest()) 191 | .pipe(gulp.dest(config.CompileDir + "/version/images")); 192 | }); 193 | 194 | 195 | //压缩js 196 | 197 | gulp.task("jsmin", function () { 198 | return gulp.src(config.CompileDir + "/**/*.{js,json}") 199 | .pipe($.plumber()) 200 | .pipe($.revCollector({ 201 | replaceReved: true 202 | })) 203 | .pipe($.uglify()) 204 | .pipe($.rev()) 205 | .pipe(gulp.dest(config.DeploymentDir)) 206 | .pipe($.rev.manifest()) 207 | .pipe(gulp.dest(config.CompileDir + "/version/js")); 208 | }); 209 | 210 | //雪碧图 211 | gulp.task("sprite", ["deploy"], function () { 212 | // return gulp.src(config.CompileDir + "/**/*.css") 213 | // // .pipe($.cssSpriter({ 214 | // // // 生成的spriter的位置 215 | // // "spriteSheet": config.CompileDir + "/images/sprite.png", 216 | // // // 生成样式文件图片引用地址的路径 217 | // // // 如下将生产:backgound:url(../images/sprite20324232.png) 218 | // // "pathToSpriteSheetFromCSS": "/images/sprite.png" 219 | // // })) 220 | // .pipe($.spriter({ 221 | // sprite: "sprite.png", 222 | // slice: "./" + config.CompileDir + "/images/", 223 | // outpath: "./" + config.CompileDir + "/images/" 224 | // })) 225 | // //产出路径 226 | // .pipe(gulp.dest(config.CompileDir)); 227 | 228 | var timestamp = +new Date(); 229 | var spritepath = "./" + config.DeploymentDir + "/images/"+"sprite"+timestamp+".png"; 230 | return gulp.src(config.DeploymentDir + "/**/*.css") 231 | .pipe($.spriter({ 232 | spriteSheet:spritepath, 233 | pathToSpriteSheetFromCSS:"../images/"+"sprite"+timestamp+".png", 234 | spritesmithOptions: { 235 | padding: 10 236 | } 237 | })) 238 | .pipe($.base64()) 239 | .pipe(gulp.dest(".")); 240 | }); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulpproject", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "devDependencies": { 13 | "browser-sync": "^2.14.0", 14 | "del": "^2.2.2", 15 | "gulp": "^3.9.1", 16 | "gulp-autoprefixer": "^3.1.1", 17 | "gulp-changed": "^1.3.2", 18 | "gulp-css": "^0.1.0", 19 | "gulp-css-base64": "^1.3.4", 20 | "gulp-css-spriter": "^0.3.3", 21 | "gulp-flatten": "^0.3.1", 22 | "gulp-htmlmin": "^2.0.0", 23 | "gulp-imagemin": "^3.0.3", 24 | "gulp-load-plugins": "^1.2.4", 25 | "gulp-minifier": "^0.1.4", 26 | "gulp-plumber": "^1.1.0", 27 | "gulp-pug": "^3.0.4", 28 | "gulp-react": "^3.1.0", 29 | "gulp-rename": "^1.2.2", 30 | "gulp-replace": "^0.5.4", 31 | "gulp-rev": "^7.1.2", 32 | "gulp-rev-collector": "^1.0.5", 33 | "gulp-sass": "^2.3.2", 34 | "gulp-tap": "^0.1.3", 35 | "gulp-uglify": "^2.0.0", 36 | "run-sequence": "^1.2.2" 37 | }, 38 | "dependencies": {} 39 | } 40 | --------------------------------------------------------------------------------