gulpfile.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. const gulp = require('gulp');
  2. const plugins = require('gulp-load-plugins')();
  3. const open = require('open');
  4. const app = {
  5. srcPath: 'app/', // 源代码
  6. devPath: 'tmp/', // 开发打包
  7. prdPath: 'dist/' // 生产打包
  8. };
  9. const JS_LIBS = [
  10. 'node_modules/angular-ui-router/release/angular-ui-router.js',
  11. 'node_modules/oclazyload/dist/ocLazyLoad.min.js',
  12. 'node_modules/angular-loading-bar/build/loading-bar.min.js',
  13. 'node_modules/angular-bootstrap/ui-bootstrap-tpls.min.js',
  14. 'node_modules/moment/moment.js',
  15. 'node_modules/angular-date-time-input/src/dateTimeInput.js',
  16. 'node_modules/angularjs-bootstrap-datetimepicker/src/js/datetimepicker.js',
  17. 'node_modules/angular-table-resize/dist/angular-table-resize.min.js',
  18. 'node_modules/angular-clipboard/angular-clipboard.js',
  19. 'node_modules/selectize/dist/js/standalone/selectize.js',
  20. 'node_modules/angular-selectize2/dist/selectize.js',
  21. 'node_modules/bootstrap-switch/dist/js/bootstrap-switch.min.js',
  22. 'node_modules/ng-dialog/js/ngDialog.js',
  23. 'node_modules/angular-ui-notification/dist/angular-ui-notification.min.js',
  24. 'node_modules/angular-utils-pagination/dirPagination.js',
  25. 'app/scripts/libs/treeTable.js',
  26. ];
  27. const CSS_APP = [
  28. 'node_modules/angular-loading-bar/build/loading-bar.min.css',
  29. 'node_modules/bootstrap-switch/dist/css/bootstrap3/bootstrap-switch.css',
  30. 'node_modules/ng-dialog/css/ngDialog.min.css',
  31. 'node_modules/ng-dialog/css/ngDialog-theme-default.css',
  32. 'node_modules/angularjs-bootstrap-datetimepicker/src/css/datetimepicker.css',
  33. 'node_modules/angular-ui-notification/dist/angular-ui-notification.min.css',
  34. 'node_modules/angular-table-resize/dist/angular-table-resize.css',
  35. 'node_modules/selectize/dist/css/selectize.css',
  36. 'app/styles/page.css',
  37. 'app/styles/timeline.css',
  38. 'app/styles/main.css'
  39. ];
  40. const JS_APP = [
  41. 'app/scripts/app.js',
  42. 'app/scripts/filters/filters.js',
  43. 'app/scripts/services/version_service.js',
  44. 'app/scripts/services/auth_service.js',
  45. 'app/scripts/services/appservice.js',
  46. 'app/scripts/services/flow_service_v1.js',
  47. 'app/scripts/services/flow_service_v2.js',
  48. 'app/scripts/services/degrade_service.js',
  49. 'app/scripts/services/systemservice.js',
  50. 'app/scripts/services/machineservice.js',
  51. 'app/scripts/services/identityservice.js',
  52. 'app/scripts/services/metricservice.js',
  53. 'app/scripts/services/param_flow_service.js',
  54. 'app/scripts/services/authority_service.js',
  55. 'app/scripts/services/cluster_state_service.js',
  56. 'app/scripts/services/gateway/api_service.js',
  57. 'app/scripts/services/gateway/flow_service.js',
  58. ];
  59. gulp.task('lib', function () {
  60. gulp.src(JS_LIBS)
  61. .pipe(plugins.concat('app.vendor.js'))
  62. .pipe(gulp.dest(app.devPath + 'js'))
  63. .pipe(plugins.uglify())
  64. .pipe(gulp.dest(app.prdPath + 'js'))
  65. .pipe(plugins.connect.reload());
  66. });
  67. /*
  68. * css任务
  69. * 在src下创建style文件夹,里面存放less文件。
  70. */
  71. gulp.task('css', function () {
  72. gulp.src(CSS_APP)
  73. .pipe(plugins.concat('app.css'))
  74. .pipe(gulp.dest(app.devPath + 'css'))
  75. .pipe(plugins.cssmin())
  76. .pipe(gulp.dest(app.prdPath + 'css'))
  77. .pipe(plugins.connect.reload());
  78. });
  79. /*
  80. * js任务
  81. * 在src目录下创建script文件夹,里面存放所有的js文件
  82. */
  83. gulp.task('js', function () {
  84. gulp.src(JS_APP)
  85. .pipe(plugins.concat('app.js'))
  86. .pipe(gulp.dest(app.devPath + 'js'))
  87. .pipe(plugins.uglify())
  88. .pipe(gulp.dest(app.prdPath + 'js'))
  89. .pipe(plugins.connect.reload());
  90. });
  91. /*
  92. * js任务
  93. * 在src目录下创建script文件夹,里面存放所有的js文件
  94. */
  95. gulp.task('jshint', function () {
  96. gulp.src(JS_APP)
  97. .pipe(plugins.jshint())
  98. .pipe(plugins.jshint.reporter());
  99. });
  100. // 每次发布的时候,可能需要把之前目录内的内容清除,避免旧的文件对新的容有所影响。 需要在每次发布前删除dist和build目录
  101. gulp.task('clean', function () {
  102. gulp.src([app.devPath, app.prdPath])
  103. .pipe(plugins.clean());
  104. });
  105. // 总任务
  106. gulp.task('build', ['clean', 'jshint', 'lib', 'js', 'css']);
  107. // 服务
  108. gulp.task('serve', ['build'], function () {
  109. plugins.connect.server({ //启动一个服务器
  110. root: [app.devPath], // 服务器从哪个路径开始读取,默认从开发路径读取
  111. livereload: true, // 自动刷新
  112. port: 1234
  113. });
  114. // 打开浏览器
  115. setTimeout(() => {
  116. open('http://localhost:8080/index_dev.htm')
  117. }, 200);
  118. // 监听
  119. gulp.watch(app.srcPath + '**/*.js', ['js']);
  120. gulp.watch(app.srcPath + '**/*.css', ['css']);
  121. });
  122. // 定义default任务
  123. gulp.task('default', ['serve']);