根据项目需要可能会出连载
项目需要现在用gulp进行js的质量检测、合并、压缩、发布,未来需要进行sass的编译、合并、压缩,html、img的压缩以及md5戳、reload等功能,暂时先测试js的质量检测、合并、压缩、发布功能。
进行本操作时,默认你已经安装好NODE+RUBY+SASS+COMPASS+GULP
步骤一:npm init 新建package.json ,其内容格式如范本
{ "name": "testGulp", "version": "0.0.1", "private": true, "scripts": { "start": "node ./bin/www" }, "dependencies": { "express": "~4.12.0", "serve-favicon": "~2.2.0", "morgan": "~1.5.0", "cookie-parser": "~1.3.5", "body-parser": "~1.12.0", "debug": "~2.1.0", "i18n": "^0.5.0", "swig": "~1.4.2", "request": "^2.53.0", "avoscloud-sdk": "^0.5.0", "multer": "^0.1.8", "qs": "^3.1.0", "pagination": "^0.4.3", "pagination-api": "^0.1.3", "cookie-session": "^1.1.0", "formidable": "^1.0.17", "fs": "^0.0.2" }, "devDependencies": { "babel-cli": "^6.5.1", "babel-core": "^6.6.4", "babel-preset-es2015": "^6.6.0", "gulp": "~3.9.0", "gulp-clean": "^0.3.1", "gulp-compass": "^2.1.0", "gulp-concat": "^2.6.0", "gulp-eslint": "^0.13.0", "gulp-livereload": "^3.8.1", "gulp-minify-css": "^1.1.5", "gulp-nodemon": "^2.0.4", "gulp-rename": "^1.2.2", "gulp-rev": "^4.0.0", "gulp-rimraf": "^0.1.1", "gulp-ruby-sass": "^1.0.5", "gulp-uglify": "^1.2.0", "tiny-lr": "^0.1.5", "gulp-notify": "^2.2.0" } }
步骤二:新建gulpfile.js 其内容格式如范本
var gulp = require('gulp'), livereload = require('gulp-livereload'), sass = require('gulp-ruby-sass'), fs= require('fs'); var uglify = require('gulp-uglify'), concat2 = require('gulp-concat'); rename = require('gulp-rename'); gulp.task('sass', function () { return sass('./public/sass/') .pipe(gulp.dest('./public/css')) .pipe(livereload()); }); gulp.task('greet', function () { console.log('Hello world! Never Bug!'); });
gulp.task('commoncss', function() {
return gulp.src(['./public/sass/header.scss','./public/sass/footer.scss'])
.pipe(concat2('main.scss'))
.pipe(rename('common.min.css'))
.pipe(gulp.dest('assets/css/'));
});
gulp.task('default', [
'sass',
'watch'
]);
步骤三:如gulp任务commoncss cmd里输入gulp commoncss 在目标生成的文件夹里可以看到我们合并的文件