截流自动化的商城平台
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

gulpfile.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /**
  2. layuiAdmin std 构建
  3. */
  4. var pkg = require('./package.json');
  5. var inds = pkg.independents;
  6. var gulp = require('gulp');
  7. var uglify = require('gulp-uglify');
  8. var minify = require('gulp-minify-css');
  9. var concat = require('gulp-concat');
  10. var rename = require('gulp-rename');
  11. var replace = require('gulp-replace');
  12. var header = require('gulp-header');
  13. var del = require('del');
  14. var gulpif = require('gulp-if');
  15. var minimist = require('minimist');
  16. //获取参数
  17. var argv = require('minimist')(process.argv.slice(2), {
  18. default: {
  19. ver: 'all'
  20. }
  21. })
  22. //注释
  23. ,note = [
  24. '/** <%= pkg.name %>-v<%= pkg.version %> <%= pkg.license %> License By <%= pkg.homepage %> */\n <%= js %>'
  25. ,{pkg: pkg, js: ';'}
  26. ]
  27. ,destDir = './dist' //构建的目标目录
  28. ,releaseDir = '../pack/layuiAdmin.pack/'+ pkg.name +'-v' + pkg.version //发行版本目录
  29. //任务
  30. ,task = {
  31. //压缩 JS
  32. minjs: function(){
  33. var src = [
  34. './src/layuiadmin/**/*.js'
  35. ,'!./src/layuiadmin/json/**/*.js'
  36. ,'!./src/layuiadmin/layui/**/*.js'
  37. ,'!./src/layuiadmin/config.js'
  38. ,'!./src/layuiadmin/lib/extend/echarts.js'
  39. ];
  40. return gulp.src(src).pipe(uglify())
  41. .pipe(header.apply(null, note))
  42. .pipe(gulp.dest(destDir + '/layuiadmin'));
  43. }
  44. //压缩 CSS
  45. ,mincss: function(){
  46. var src = [
  47. './src/layuiadmin/**/*.css'
  48. ,'!./src/layuiadmin/layui/**/*.css'
  49. ]
  50. ,noteNew = JSON.parse(JSON.stringify(note));
  51. noteNew[1].js = '';
  52. return gulp.src(src).pipe(minify({
  53. compatibility: 'ie7'
  54. })).pipe(header.apply(null, noteNew))
  55. .pipe(gulp.dest(destDir + '/layuiadmin'));
  56. }
  57. //复制文件夹
  58. ,mv: function(){
  59. gulp.src('./src/layuiadmin/json/**/*')
  60. .pipe(gulp.dest(destDir + '/layuiadmin/json'));
  61. gulp.src('./src/layuiadmin/lib/extend/echarts.js')
  62. .pipe(gulp.dest(destDir + '/layuiadmin/lib/extend'));
  63. gulp.src('./src/layuiadmin/config.js')
  64. .pipe(gulp.dest(destDir + '/layuiadmin'));
  65. gulp.src('./src/layuiadmin/tpl/**/*')
  66. .pipe(gulp.dest(destDir + '/layuiadmin/tpl'));
  67. gulp.src('./src/layuiadmin/style/res/**/*')
  68. .pipe(gulp.dest(destDir + '/layuiadmin/style/res'));
  69. gulp.src('./src/layuiadmin/style/res/*')
  70. .pipe(gulp.dest(destDir + '/layuiadmin/style/res'));
  71. return gulp.src('./src/views/**/*')
  72. .pipe(gulp.dest(destDir + '/views'));
  73. }
  74. //复制 layui
  75. ,layui: function(){
  76. return gulp.src('../../../../res/layui/rc/**/*')
  77. .pipe(gulp.dest('./dev-std/layuiadmin/layui'))
  78. .pipe(gulp.dest('./src/layuiadmin/layui'))
  79. .pipe(gulp.dest('./dist/layuiadmin/layui'))
  80. }
  81. };
  82. //清理
  83. gulp.task('clear', function(cb) {
  84. return del(['./dist/*'], cb);
  85. });
  86. gulp.task('minjs', task.minjs);
  87. gulp.task('mincss', task.mincss);
  88. gulp.task('mv', task.mv);
  89. gulp.task('layui', task.layui);
  90. gulp.task('src', function(){ //命令:gulp src
  91. return gulp.src('./dev-std/**/*')
  92. .pipe(gulp.dest('./src'));
  93. });
  94. //构建核心源文件
  95. gulp.task('default', ['clear', 'src'], function(){ //命令:gulp
  96. for(var key in task){
  97. task[key]();
  98. }
  99. });
  100. //发行 - layuiAdmin 官方使用
  101. gulp.task('release', ['layui'], function(){ //命令:gulp && gulp release
  102. //复制核心文件
  103. gulp.src('./dist/**/*')
  104. .pipe(gulp.dest(releaseDir + '/dist'));
  105. gulp.src('./src/**/*')
  106. .pipe(gulp.dest(releaseDir + '/src'));
  107. //复制帮助文件
  108. gulp.src([
  109. './帮助/*'
  110. ,'!./帮助/说明.txt'
  111. ]).pipe(gulp.dest(releaseDir + '/帮助'));
  112. gulp.src([
  113. './帮助/说明.txt'
  114. ]).pipe(gulp.dest(releaseDir));
  115. //说明
  116. gulp.src('../pack/说明.txt')
  117. .pipe(gulp.dest('../pack/layuiAdmin.pack'));
  118. //复制 gulpfile
  119. return gulp.src([
  120. 'gulpfile.js'
  121. ,'package.json'
  122. ]).pipe(gulp.dest(releaseDir));
  123. });