当前位置: 首页 > news >正文

龙岗网站建设服务/seo公司系统

龙岗网站建设服务,seo公司系统,神华集团 两学一做 网站,炫佑网站建设这里是gulp入门的一些操作,实现了编译sass文件、压缩、合并、添加版本号等基本功能。 友情提示,如果npm出现无法下载可以安装 cnpm。在安装完Nodejs 后 [html] view plaincopy npm install cnpm -g --registryhttps://registry.npm.taobao.org 完成后可…

这里是gulp入门的一些操作,实现了编译sass文件、压缩、合并、添加版本号等基本功能。

友情提示,如果npm出现无法下载可以安装 cnpm。在安装完Nodejs 后 

[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. npm install cnpm -g --registry=https://registry.npm.taobao.org  

完成后可

[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. cnpm -v  

查看安装结果

1.安装Nodejs

选择合适的版本下载Nodejs

2.安装全局gulp

[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. npm install --global gulp-cli  

 

3.进入项目目录(之后的操作全是在此目录下进行)

[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. cd desktop/myprogram  

 

4.初始化package.json

[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. npm init  

 

5.安装项目gulp

 

[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. npm install --save-dev gulp  

 

6.安装插件

[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. npm install gulp-htmlmin gulp-imagemin imagemin-pngcrush gulp-jshint jshint  gulp-uglify gulp-notify gulp-useref gulp-load-plugins  gulp-clean-css gulp-sass  gulp-if gulp-users gulp-rev gulp-rev-collector  —save-dev  


7.新建gulpfile.js

[javascript] view plain copy 在CODE上查看代码片派生到我的代码片
  1. var gulp = require('gulp');  
  2.     gulp.task('default', function() {  
  3.         // place code for your default task here  
  4.     });  


8.测试

在终端输入命令

[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. gulp  


9.附上index.html(压缩css、js部分) 、package.json 和 gulpfile.js

index.html

[html] view plain copy 在CODE上查看代码片派生到我的代码片
  1. <link rel="shortcut icon" href="images/favicon.ico">  
  2. <!-- build:css lib/main.css -->  
  3. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">  
  4. <link rel="stylesheet" type="text/css" href="css/main.css">  
  5. <link rel="stylesheet" type="text/css" href="css/common.css">  
  6. <!-- endbuild -->  
  7.   
  8. <!-- build:js lib/main.js -->  
  9. <script type="text/javascript" src="js/jquery.min.js"></script>  
  10. <script type="text/javascript" src="js/bootstrap.min.js"></script>  
  11. <script type="text/javascript" src="js/route.js"></script>  
  12. <script type="text/javascript" src="js/main.js"></script>  
  13. <!-- endbuild -->  


package.json

[javascript] view plain copy 在CODE上查看代码片派生到我的代码片
  1. "devDependencies": {  
  2.     "del": "^2.2.0",  
  3.     "gulp": "^3.9.1",  
  4.     "gulp-clean-css": "^2.0.8",  
  5.     "gulp-concat": "^2.6.0",  
  6.     "gulp-htmlmin": "^2.0.0",  
  7.     "gulp-if": "^2.0.1",  
  8.     "gulp-imagemin": "^3.0.1",  
  9.     "gulp-jshint": "^2.0.1",  
  10.     "gulp-load-plugins": "^1.2.4",  
  11.     "gulp-notify": "^2.2.0",  
  12.     "gulp-rev": "^7.0.0",  
  13.     "gulp-rev-collector": "^1.0.3",  
  14.     "gulp-sass": "^2.3.1",  
  15.     "gulp-sequence": "^0.4.5",  
  16.     "gulp-uglify": "^1.5.3",  
  17.     "gulp-useref": "^3.1.0",  
  18.     "imagemin-pngcrush": "^5.0.0",  
  19.     "jshint": "^2.9.2"  
  20.   }  


gulpfile.js

[javascript] view plain copy 在CODE上查看代码片派生到我的代码片
  1. 'use strict';  
  2. var gulp = require('gulp'),  
  3.     $ = require("gulp-load-plugins")(),  
  4.     sass = require("gulp-sass"),  
  5.     rev = require("gulp-rev"),  
  6.     del = require('del');  
  7.   
  8. gulp.task('default', function() {  
  9.   gulp.run('styles', 'jshint');  
  10.   gulp.watch('src/styles/*.scss', ['styles']);  
  11. });  
  12.   
  13. gulp.task('build', $.sequence('cpfiles', 'useref', 'cphtml', 'revfile',  
  14.           'revhtml', 'delfiles', 'img','htmlmin'));  
  15.   
  16.   
  17. gulp.task('htmlmin', function() {  
  18.   return gulp.src(['dist/*/*.html', 'dist/*.html'])  
  19.     .pipe($.htmlmin({collapseWhitespace: true}))  
  20.     .pipe(gulp.dest('dist/'))  
  21.     .pipe($.notify({ message: 'htmlmin task done' }));  
  22. });  
  23.   
  24. gulp.task('delfiles', function(){  
  25.   del([  
  26.     'dist/js',  
  27.     'dist/css',  
  28.     'dist/styles',  
  29.     'dist/lib/index.html',  
  30.     'dist/lib/rev-manifest.json'  
  31.   ]);  
  32. })  
  33.   
  34. gulp.task('revhtml', function () {  
  35.   return gulp.src(['dist/lib/rev-manifest.json', 'dist/lib/index.html'])  
  36.     .pipe($.revCollector())  
  37.     .pipe(gulp.dest('dist/'))  
  38.     .pipe($.notify({ message: 'revhtml task done' }));  
  39. });  
  40.   
  41. gulp.task('revfile', function(){  
  42.   return gulp.src(['dist/lib/*.css', 'dist/lib/*.js'])  
  43.     .pipe($.rev())  
  44.     .pipe(gulp.dest('dist/lib/'))  
  45.     .pipe(rev.manifest({  
  46.       path: 'rev-manifest.json',  
  47.       merge: true  
  48.     }))  
  49.     .pipe(gulp.dest("dist/lib/"))  
  50.     .pipe($.notify({ message: 'revfile task done' }));  
  51. });  
  52.   
  53. gulp.task('cphtml', function(){  
  54.   return gulp.src('dist/*.html')  
  55.     .pipe(gulp.dest('dist/lib/'))  
  56.     .pipe($.notify({ message: 'copyhtml task done' }));  
  57. })  
  58.   
  59. gulp.task('useref', function() {  
  60.   return gulp.src('dist/*.html')  
  61.     .pipe($.useref())  
  62.     .pipe($.if('*.js', $.uglify()))  
  63.     .pipe($.if('*.css', $.cleanCss({compatibility: 'ie8'})))  
  64.     .pipe(gulp.dest('dist/'))  
  65.     .pipe($.notify({ message: 'useref task done' }));  
  66. });  
  67.   
  68. gulp.task('cpfiles', ['styles'], function(){  
  69.   return gulp.src(['src/*/*','src/*'])  
  70.     .pipe(gulp.dest('dist/'))  
  71.     .pipe($.notify({ message: 'copyfiles task done' }));  
  72. })  
  73.   
  74. gulp.task('img', function() {  
  75.   return gulp.src('dist/images/*.*')  
  76.     .pipe($.imagemin({  
  77.         progressive: true,  
  78.         svgoPlugins: [{removeViewBox: false}],  
  79.         use: [$.imagemin()]  
  80.     }))  
  81.     .pipe(gulp.dest('dist/images/'))  
  82.     .pipe($.notify({ message: 'img task done' }));  
  83. });  
  84.   
  85. gulp.task('styles', function(){  
  86.   return gulp.src('src/styles/*.scss')  
  87.     .pipe(sass().on('error', sass.logError))  
  88.     .pipe(gulp.dest('src/css'))  
  89.     .pipe($.notify({ message: 'sass task done' }));  
  90. })  
  91.   
  92. gulp.task('jshint', function() {  
  93.   return gulp.src(['src/js/main.js','src/js/route.js'])  
  94.     .pipe($.jshint())  
  95.     .pipe($.jshint.reporter('default'))  
  96.     .pipe($.notify({ message: 'jshint task done' }));  
  97. });  
  98.   
  99. gulp.task('clean', function(){  
  100.   del([  
  101.     'dist/'  
  102.     ]);  
  103. })  


文件结构,上层为 desktop/myprogram/

转载于:https://www.cnblogs.com/sxz2008/p/6378067.html

http://www.lbrq.cn/news/945865.html

相关文章:

  • 哪些香港网站不能访问/郑州seo技术培训班
  • 东莞市建设公共交易中心网站/seo关键词推广怎么做
  • 个人做众筹网站合法吗/网页设计制作
  • 厦门网站建设公司哪个好/定制建站网站建设
  • 嘉兴网站建设哪家好/seo体系百科
  • 网站空间指的是什么/怎样建立自己网站
  • 怎样优化网站排名靠前/百度引擎提交入口
  • 网站做微信支付/百度竞价返点开户
  • 制作网站的方法/网址搜索域名查询
  • 鄂尔多斯做网站/免费线上培训平台
  • 运城做网站/网络推广的优势
  • 注册公司名称查询/广州网站优化费用
  • 公司网站开发项目外包方案/网络营销的含义的理解
  • 一家公司做网站需要什么资料/关键词优化排名查询
  • 做网站公司简介模版/网站目录
  • 易捷商城小程序/杭州新站整站seo
  • 石家庄网站建设电话/网拍外宣怎么推广
  • 做淘宝客网站的流程/怎么自己做网站
  • 网站怎么做才可以做评价/seoyoon
  • 备案时填写 网站内容/网络推广软文范文
  • 建站行业严重产能过剩/微博推广平台
  • 网站做可信认证多少钱/网站排名软件
  • 顺义做网站的公司/产品市场营销策划方案
  • 有什么网站专门做美食的吗/seo收费还是免费
  • 左权网站建设/seo教程优化
  • 做微信商城网站/郑州seo方案
  • 网站公司怎么做运营/三叶草gy5987
  • 学怎么做建筑标书哪个网站/自动外链工具
  • 给企业做网站挣钱吗/seo网站优化推广费用
  • 济南市城乡建设委员会网站电话/seo搜索优化待遇
  • Android 修改系统时间源码阅读
  • C++ 多线程同步机制详解:互斥锁、条件变量与原子操作
  • XCTF-crypto-幂数加密
  • 暑期算法训练.8
  • 2025最新MySQL面试题实战记录,互联网公司常问题目
  • OSPF路由协议单区域