var gulp = require('gulp'); var debug = require ('gulp-debug'); var watch = require('gulp-watch'); var uglify = require('gulp-uglify'); var concat = require('gulp-concat'); var rename = require('gulp-rename'); var rimraf = require('gulp-rimraf'); var watchLess = require('gulp-watch-less'); var less = require('gulp-less'); var runSequence = require('run-sequence'); var _ = require('lodash'); var clean = require('gulp-clean'); var plugins = require('gulp-load-plugins')({ lazy: true }); var proxy = require('http-proxy-middleware'); var paths = { // using framework version of jquery scripts: [ 'static/vendors/traceur/traceur.min.js', 'static/vendors/lodash/dist/lodash.min.js', 'static/vendors/angular/angular.min.js', 'static/vendors/angular-route/angular-route.min.js', 'static/vendors/jquery/dist/jquery.min.js', 'static/vendors/jquery-ui/jquery-ui.min.js', 'static/vendors/bootstrap/dist/js/bootstrap.min.js', 'static/vendors/zTree/js/jquery.ztree.core.js', 'static/vendors/flatpickr/dist/flatpickr.min.js', 'static/vendors/flatpickr/dist/l10n/zh.js', 'static/vendors/sweetalert/dist/sweetalert.min.js', 'static/vendors/ng-file-upload-shim/ng-file-upload.min.js', 'static/vendors/ng-file-upload-shim/ng-file-upload-shim.min.js', 'static/vendors/toastr/toastr.min.js', 'static/vendors/smalot-bootstrap-datetimepicker/js/bootstrap-datetimepicker.js', 'static/vendors/smalot-bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js', 'static/vendors/imageviewer/dist/viewer.js', 'static/vendors/ngDraggable/ngDraggable.js', 'static/js/utils/form-builder.js', 'static/js/utils/uuid.js', 'static/js/utils/jquery.base64.min.js', 'static/js/utils/des.js', 'static/js/utils/jquery.md5.js', 'static/js/app.js', 'static/js/business/module.js', 'static/js/billing_cfg_guide/module.js', 'static/js/budget_form_customize/module.js', 'static/js/budget_forms/module.js', 'static/js/utils/http.js', 'static/js/saved_form/module.js', 'static/js/config_center/module.js', 'static/js/system_config/module.js', 'static/js/travel_expense/module.js', 'static/js/travel_expense_todos/module.js', 'static/js/forms_center/module.js', 'static/js/messages_center/module.js', 'static/js/templates_center/module.js', 'static/js/expend_standard/module.js', 'static/js/registry/module.js', 'static/js/work_flow/module.js' ] }; var path = { 'dev': './', 'build': 'static/js/build/', 'dist': 'dist/' }; gulp.task('less', function(){ return gulp.src('static/css/**/*.less') .pipe(watchLess('static/css/**/*.less')) .pipe(debug()) .pipe(less()) .pipe(gulp.dest('static/css/')); }) gulp.task('prod:clean', function(done){ return gulp .src(path.dist, { read: false }) .pipe(rimraf({ force: true }, done)); }) gulp.task('prod:copyAll', function(){ return gulp.src(['static/**/*']) .pipe(gulp.dest(path.dist + 'static/')); }) gulp.task('prod:copyIndex', function(){ return gulp.src(['index.html']) .pipe(gulp.dest(path.dist)); }) gulp.task('prod:minify', function(){ return gulp.src(_.map(paths.scripts, o=> path.dist + o)) .pipe(concat('all.js')) .pipe(gulp.dest(path.dist+path.build)) .pipe(rename('all.min.js')) .pipe(uglify()) .pipe(gulp.dest(path.dist+path.build)) }) gulp.task('prod:inject', function () { var target = gulp.src('./index.html'); var sources = gulp.src([ path.dist+path.build+'all.min.js' ], { read: false }); return target.pipe(plugins.inject(sources, { ignorePath: 'dist/', addRootSlash: true })) .pipe(gulp.dest(path.dist)); }); gulp.task('build:prod', function(done){ runSequence( 'prod:clean', 'prod:copyAll', 'prod:minify', 'prod:inject', 'prod:clearnSrc', done); }); gulp.task('prod:clearnSrc', function(){ return gulp.src(_.map(paths.scripts, o=> path.dist + o), {read: false}) .pipe(clean()); }); gulp.task('dev:watch', function () { gulp.watch('static/css/**/*.less', ['less']); }); gulp.task('connect:dev', function() { plugins.connect.server({ root: [path.dev], port: 80, livereload: false, fallback: 'index.html', middleware: function(connect, opt) { return [ proxy('/travel-web', { // target: 'http://192.168.31.137:8080', // target: 'http://10.4.32.37:8080', target: 'http://10.4.32.57:80/', // target: 'http://192.168.31.17:8080/', // target: 'http://192.168.31.144:8080', // target: 'http://192.168.31.17:8080', // target: 'http://192.168.31.30:8080', // target: 'http://192.168.31.53:8090', // target: 'http://192.168.31.205', // target: 'http://192.168.31.89:8090', // target: 'http://122.114.176.216:8080/', //// target: 'http://202.98.157.47:8081/', // target: 'http://10.4.68.58', // target: 'http://10.4.32.58:8080', // target: 'http://localhost:8080', // target: 'http://192.168.31.172:80', changeOrigin:true }) ] } }); }); gulp.task('connect:prod', function() { plugins.connect.server({ root: [path.dist], port: 8082, livereload: false, fallback: 'index.html', middleware: function(connect, opt) { return [ proxy('/travel-web', { target: 'http://122.114.176.216:8080/', changeOrigin:true }) ] } }); }); gulp.task('run:dev', function(done){ runSequence( 'dev:watch', 'connect:dev', done); });